详解spring boot集成ehcache 2.x 用于hibernate二级缓存

本文将介绍如何在spring boot中集成ehcache作为hibernate的二级缓存。各个框架版本如下

  1. spring boot:1.4.3.RELEASE
  2. spring framework: 4.3.5.RELEASE
  3. hibernate:5.0.1.Final(spring-boot-starter-data-jpa默认依赖)
  4. ehcache:2.10.3

项目依赖

<dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-cache</artifactId>
</dependency>

<dependency>
 <groupId>org.hibernate</groupId>
 <artifactId>hibernate-ehcache</artifactId>
 <exclusions>
  <exclusion>
   <groupId>net.sf.ehcache</groupId>
   <artifactId>ehcache-core</artifactId>
  </exclusion>
 </exclusions>
</dependency>

<dependency>
 <groupId>net.sf.ehcache</groupId>
 <artifactId>ehcache</artifactId>
 <version>2.10.3</version>
</dependency>

Ehcache简介

ehcache是一个纯Java的缓存框架,既可以当做一个通用缓存使用,也可以作为将其作为hibernate的二级缓存使用。缓存数据可选择如下三种存储方案

  1. MemoryStore – On-heap memory used to hold cache elements. This tier is subject to Java garbage collection.
  2. OffHeapStore – Provides overflow capacity to the MemoryStore. Limited in size only by available RAM. Not subject to Java garbage collection (GC). Available only with Terracotta BigMemory products.
  3. DiskStore – Backs up in-memory cache elements and provides overflow capacity to the other tiers.

hibernate二级缓存配置

hibernate的二级缓存支持entity和query层面的缓存,org.hibernate.cache.spi.RegionFactory各类可插拔的缓存提供商与hibernate的集成。

# 打开hibernate统计信息
spring.jpa.properties.hibernate.generate_statistics=true

# 打开二级缓存
spring.jpa.properties.hibernate.cache.use_second_level_cache=true

# 打开查询缓存
spring.jpa.properties.hibernate.cache.use_query_cache=true

# 指定缓存provider
spring.jpa.properties.hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory

# 配置shared-cache-mode
spring.jpa.properties.javax.persistence.sharedCache.mode=ENABLE_SELECTIVE

关于hibernate缓存相关的所有配置可参考hibernate5.0官方文档#缓存

ehcache配置文件

ehcache 2.x配置文件样板参考官方网站提供的ehcache.xml。本例中使用的配置文件如下所示

<?xml version="1.0" encoding="UTF-8"?>

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation="http://www.ehcache.org/ehcache.xsd"
  updateCheck="true" monitoring="autodetect"
  dynamicConfig="true">

 <diskStore path="user.dir/cache"/>
 <transactionManagerLookup class="net.sf.ehcache.transaction.manager.DefaultTransactionManagerLookup"
        properties="jndiName=java:/TransactionManager" propertySeparator=";"/>
 <cacheManagerEventListenerFactory class="com.yangyi.base.ehcache.CustomerCacheManagerEventListenerFactory" properties=""/>

 <defaultCache
  maxEntriesLocalHeap="0"
  eternal="false"
  timeToIdleSeconds="1200"
  timeToLiveSeconds="1200">
  <!--<terracotta/>-->
 </defaultCache>

 <cache name="entityCache"
   maxEntriesLocalHeap="1000"
   maxEntriesLocalDisk="10000"
   eternal="false"
   diskSpoolBufferSizeMB="20"
   timeToIdleSeconds="10"
   timeToLiveSeconds="20"
   memoryStoreEvictionPolicy="LFU"
   transactionalMode="off">
  <persistence strategy="localTempSwap"/>
  <cacheEventListenerFactory class="com.yangyi.base.ehcache.CustomerCacheEventListenerFactory" />
 </cache>

 <cache name="org.hibernate.cache.internal.StandardQueryCache"
   maxEntriesLocalHeap="5" eternal="false" timeToLiveSeconds="120">
  <persistence strategy="localTempSwap" />
  <cacheEventListenerFactory class="com.yangyi.base.ehcache.CustomerCacheEventListenerFactory" />
 </cache>

 <cache name="org.hibernate.cache.spi.UpdateTimestampsCache"
   maxEntriesLocalHeap="5000" eternal="true">
  <persistence strategy="localTempSwap" />
  <cacheEventListenerFactory class="com.yangyi.base.ehcache.CustomerCacheEventListenerFactory" />
 </cache>
</ehcache>

ehcache事件监听

在ehcache中,有两大类事件,一是cacheManager相关的事件,如cache的init/added等;二是cahche相关的事件,如cache put/expire等。在ehcache中,默认没有这两类事件的监听器,需要自主实现监听器以及监听器工厂类,然后配置到ehcache.xml中,方可生效。

上述ehcache.xml配置中,给自定义cache都配置了cacheEventListenerFactory,用于监听缓存事件。同时也配置了cacheManager Factory实现类。具体实现代码如下

CacheManagerEventListener简单实现

package com.yangyi.base.ehcache;

import net.sf.ehcache.CacheException;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Status;
import net.sf.ehcache.event.CacheManagerEventListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * ehcache customer cacheManagerEventListener
 * Created by yangjinfeng on 2017/1/5.
 */
public class CustomerCacheManagerEventListener implements CacheManagerEventListener {

 private Logger logger = LoggerFactory.getLogger(getClass());

 private final CacheManager cacheManager;

 public CustomerCacheManagerEventListener(CacheManager cacheManager) {
  this.cacheManager = cacheManager;
 }

 @Override
 public void init() throws CacheException {
  logger.info("init ehcache...");
 }

 @Override
 public Status getStatus() {
  return null;
 }

 @Override
 public void dispose() throws CacheException {
  logger.info("ehcache dispose...");
 }

 @Override
 public void notifyCacheAdded(String s) {
  logger.info("cacheAdded... {}", s);
  logger.info(cacheManager.getCache(s).toString());
 }

 @Override
 public void notifyCacheRemoved(String s) {

 }
}

CacheManagerEventListenerFactory的简单实现

package com.yangyi.base.ehcache;

import net.sf.ehcache.CacheManager;
import net.sf.ehcache.event.CacheManagerEventListener;
import net.sf.ehcache.event.CacheManagerEventListenerFactory;

import java.util.Properties;

/**
 * Created by yangjinfeng on 2017/1/5.
 */
public class CustomerCacheManagerEventListenerFactory extends CacheManagerEventListenerFactory {
 @Override
 public CacheManagerEventListener createCacheManagerEventListener(CacheManager cacheManager, Properties properties) {
  return new CustomerCacheManagerEventListener(cacheManager);
 }
}

CacheEventListener的简单实现

package com.yangyi.base.ehcache;

import net.sf.ehcache.CacheException;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element;
import net.sf.ehcache.event.CacheEventListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by yangjinfeng on 2017/1/5.
 */
public class CustomerCacheEventListener implements CacheEventListener {

 private Logger logger = LoggerFactory.getLogger(getClass());

 @Override
 public void notifyElementRemoved(Ehcache ehcache, Element element) throws CacheException {
  logger.info("cache removed. key = {}, value = {}", element.getObjectKey(), element.getObjectValue());
 }

 @Override
 public void notifyElementPut(Ehcache ehcache, Element element) throws CacheException {
  logger.info("cache put. key = {}, value = {}", element.getObjectKey(), element.getObjectValue());
 }

 @Override
 public void notifyElementUpdated(Ehcache ehcache, Element element) throws CacheException {
  logger.info("cache updated. key = {}, value = {}", element.getObjectKey(), element.getObjectValue());
 }

 @Override
 public void notifyElementExpired(Ehcache ehcache, Element element) {
  logger.info("cache expired. key = {}, value = {}", element.getObjectKey(), element.getObjectValue());
 }

 @Override
 public void notifyElementEvicted(Ehcache ehcache, Element element) {
  logger.info("cache evicted. key = {}, value = {}", element.getObjectKey(), element.getObjectValue());
 }

 @Override
 public void notifyRemoveAll(Ehcache ehcache) {
  logger.info("all elements removed. cache name = {}", ehcache.getName());
 }

 @Override
 public Object clone() throws CloneNotSupportedException {
  throw new CloneNotSupportedException();
 }

 @Override
 public void dispose() {
  logger.info("cache dispose.");
 }
}

CacheEventListenerFactory的简单实现

package com.yangyi.base.ehcache;

import net.sf.ehcache.event.CacheEventListener;
import net.sf.ehcache.event.CacheEventListenerFactory;

import java.util.Properties;

/**
 * Created by yangjinfeng on 2017/1/5.
 */
public class CustomerCacheEventListenerFactory extends CacheEventListenerFactory {
 @Override
 public CacheEventListener createCacheEventListener(Properties properties) {
  return new CustomerCacheEventListener();
 }
}

完成上述事件监听器的实现和配置后,我们可以启动应用,查看下相应事件监听器中输出的log,以验证是否生效

2017-01-07 10:27:07.810 INFO 4264 --- [   main] com.yangyi.Application     : Starting Application on yangjinfeng-pc with PID 4264 (E:\JavaWorkSpace\spring-boot-ehcache3-hibernate5-jcache\target\classes started by yangjinfeng in E:\JavaWorkSpace\spring-boot-ehcache3-hibernate5-jcache)
2017-01-07 10:27:07.810 INFO 4264 --- [   main] com.yangyi.Application     : No active profile set, falling back to default profiles: default
2017-01-07 10:27:07.865 INFO 4264 --- [   main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@2ef3eef9: startup date [Sat Jan 07 10:27:07 CST 2017]; root of context hierarchy
2017-01-07 10:27:09.155 INFO 4264 --- [   main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$6eb4eae9] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-01-07 10:27:09.191 INFO 4264 --- [   main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cache.annotation.ProxyCachingConfiguration' of type [class org.springframework.cache.annotation.ProxyCachingConfiguration$$EnhancerBySpringCGLIB$$b7c72107] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-01-07 10:27:09.206 INFO 4264 --- [   main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration' of type [class org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration$$EnhancerBySpringCGLIB$$ac3ae5ab] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-01-07 10:27:09.285 INFO 4264 --- [   main] trationDelegate$BeanPostProcessorChecker : Bean 'spring.cache-org.springframework.boot.autoconfigure.cache.CacheProperties' of type [class org.springframework.boot.autoconfigure.cache.CacheProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-01-07 10:27:09.291 INFO 4264 --- [   main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.cache.CacheManagerCustomizers' of type [class org.springframework.boot.autoconfigure.cache.CacheManagerCustomizers] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-01-07 10:27:09.293 INFO 4264 --- [   main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.cache.EhCacheCacheConfiguration' of type [class org.springframework.boot.autoconfigure.cache.EhCacheCacheConfiguration$$EnhancerBySpringCGLIB$$46d9b2a9] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-01-07 10:27:09.418 INFO 4264 --- [   main] .y.b.e.CustomerCacheManagerEventListener : init ehcache...
2017-01-07 10:27:09.487 INFO 4264 --- [   main] .y.b.e.CustomerCacheManagerEventListener : cacheAdded... org.hibernate.cache.spi.UpdateTimestampsCache
2017-01-07 10:27:09.487 INFO 4264 --- [   main] .y.b.e.CustomerCacheManagerEventListener : [ name = org.hibernate.cache.spi.UpdateTimestampsCache status = STATUS_ALIVE eternal = true overflowToDisk = true maxEntriesLocalHeap = 5000 maxEntriesLocalDisk = 0 memoryStoreEvictionPolicy = LRU timeToLiveSeconds = 0 timeToIdleSeconds = 0 persistence = LOCALTEMPSWAP diskExpiryThreadIntervalSeconds = 120 cacheEventListeners: com.yangyi.base.ehcache.CustomerCacheEventListener ; orderedCacheEventListeners: maxBytesLocalHeap = 0 overflowToOffHeap = false maxBytesLocalOffHeap = 0 maxBytesLocalDisk = 0 pinned = false ]
2017-01-07 10:27:09.487 INFO 4264 --- [   main] .y.b.e.CustomerCacheManagerEventListener : cacheAdded... org.hibernate.cache.internal.StandardQueryCache
2017-01-07 10:27:09.487 INFO 4264 --- [   main] .y.b.e.CustomerCacheManagerEventListener : [ name = org.hibernate.cache.internal.StandardQueryCache status = STATUS_ALIVE eternal = false overflowToDisk = true maxEntriesLocalHeap = 5 maxEntriesLocalDisk = 0 memoryStoreEvictionPolicy = LRU timeToLiveSeconds = 120 timeToIdleSeconds = 0 persistence = LOCALTEMPSWAP diskExpiryThreadIntervalSeconds = 120 cacheEventListeners: com.yangyi.base.ehcache.CustomerCacheEventListener ; orderedCacheEventListeners: maxBytesLocalHeap = 0 overflowToOffHeap = false maxBytesLocalOffHeap = 0 maxBytesLocalDisk = 0 pinned = false ]
2017-01-07 10:27:09.503 INFO 4264 --- [   main] .y.b.e.CustomerCacheManagerEventListener : cacheAdded... entityCache
2017-01-07 10:27:09.503 INFO 4264 --- [   main] .y.b.e.CustomerCacheManagerEventListener : [ name = entityCache status = STATUS_ALIVE eternal = false overflowToDisk = true maxEntriesLocalHeap = 1000 maxEntriesLocalDisk = 10000 memoryStoreEvictionPolicy = LFU timeToLiveSeconds = 20 timeToIdleSeconds = 10 persistence = LOCALTEMPSWAP diskExpiryThreadIntervalSeconds = 120 cacheEventListeners: com.yangyi.base.ehcache.CustomerCacheEventListener ; orderedCacheEventListeners: maxBytesLocalHeap = 0 overflowToOffHeap = false maxBytesLocalOffHeap = 0 maxBytesLocalDisk = 0 pinned = false ]
2017-01-07 10:27:09.503 INFO 4264 --- [   main] trationDelegate$BeanPostProcessorChecker : Bean 'ehCacheCacheManager' of type [class net.sf.ehcache.CacheManager] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-01-07 10:27:09.503 INFO 4264 --- [   main] trationDelegate$BeanPostProcessorChecker : Bean 'cacheManager' of type [class org.springframework.cache.ehcache.EhCacheCacheManager] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-01-07 10:27:09.503 INFO 4264 --- [   main] trationDelegate$BeanPostProcessorChecker : Bean 'cacheAutoConfigurationValidator' of type [class org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration$CacheManagerValidator] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-01-07 10:27:09.829 INFO 4264 --- [   main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-01-07 10:27:09.839 INFO 4264 --- [   main] o.apache.catalina.core.StandardService : Starting service Tomcat
2017-01-07 10:27:09.839 INFO 4264 --- [   main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.6
2017-01-07 10:27:09.924 INFO 4264 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]  : Initializing Spring embedded WebApplicationContext
2017-01-07 10:27:09.924 INFO 4264 --- [ost-startStop-1] o.s.web.context.ContextLoader   : Root WebApplicationContext: initialization completed in 2061 ms

2017-01-07 10:32:41.876 INFO 4264 --- [nio-8080-exec-1] c.y.b.e.CustomerCacheEventListener  : cache put. key = com.yangyi.entity.User#1, value = org.hibernate.cache.ehcache.internal.strategy.AbstractReadWriteEhcacheAccessStrategy$Item@1c13194d
2017-01-07 10:32:41.877 INFO 4264 --- [nio-8080-exec-1] c.y.b.e.CustomerCacheEventListener  : cache put. key = com.yangyi.entity.Authority#1, value = org.hibernate.cache.ehcache.internal.strategy.AbstractReadWriteEhcacheAccessStrategy$Item@2accc177
2017-01-07 10:32:41.878 INFO 4264 --- [nio-8080-exec-1] c.y.b.e.CustomerCacheEventListener  : cache put. key = com.yangyi.entity.Authority#2, value = org.hibernate.cache.ehcache.internal.strategy.AbstractReadWriteEhcacheAccessStrategy$Item@2b3b9c7e
2017-01-07 10:32:41.879 INFO 4264 --- [nio-8080-exec-1] c.y.b.e.CustomerCacheEventListener  : cache put. key = com.yangyi.entity.Authority#3, value = org.hibernate.cache.ehcache.internal.strategy.AbstractReadWriteEhcacheAccessStrategy$Item@4c31e58c

注解方式使用二级缓存

要使用entity cache,需要在entity上配上相应的注解方可生效。javax.persistence.Cacheable注解标记该entity使用二级缓存,org.hibernate.annotations.Cache注解指定缓存策略,以及存放到哪个缓存区域。

有关缓存策略详细信息可参考hibernate5.0官方文档#缓存

package com.yangyi.entity;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import javax.persistence.Cacheable;
import javax.persistence.Entity;
import javax.persistence.JoinTable;

@Entity
@Table(name = "users")
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "entityCache")
public class User implements Serializable {

}

最后,我们需要在spring boot应用层面打开cache功能,使用org.springframework.cache.annotation.EnableCaching注解

package com.yangyi;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;

@SpringBootApplication
@EnableCaching
public class Application {

 public static void main(String[] args) {
  SpringApplication.run(Application.class, args);
 }
}

完整代码

完整代码示例见github

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

(0)

相关推荐

  • 详解SpringBoot缓存的实例代码(EhCache 2.x 篇)

    本篇介绍了SpringBoot 缓存(EhCache 2.x 篇),分享给大家,具体如下: SpringBoot 缓存 在 spring Boot中,通过@EnableCaching注解自动化配置合适的缓存管理器(CacheManager),Spring Boot根据下面的顺序去侦测缓存提供者: Generic JCache (JSR-107) EhCache 2.x Hazelcast Infinispan Redis Guava Simple 关于 Spring Boot 的缓存机制: 高速

  • Spring Boot缓存实战 EhCache示例

    Spring boot默认使用的是SimpleCacheConfiguration,即使用ConcurrentMapCacheManager来实现缓存.但是要切换到其他缓存实现也很简单 pom文件 在pom中引入相应的jar包 <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web<

  • springboot+EHcache 实现文章浏览量的缓存和超时更新

    问题描述 当我们需要统计文章的浏览量的时候,最常规的做法就是: 1.访问文章链接www.abc.com/article/{id} 2.在控制层获取Article实体 3.得到文章浏览量count并且count++ 4.最后update实体Article. 这么做对没有访问量的网站来说很棒,如果网站访问量很大,这么不停的读写数据库,会对服务器造成很大的压力. 解决思路 引入Ehcache,将文章的访问量存在cache中,每点击一次文章,将cache中的count加1.在有效的时间内访问文章只是将c

  • 详解spring boot集成ehcache 2.x 用于hibernate二级缓存

    本文将介绍如何在spring boot中集成ehcache作为hibernate的二级缓存.各个框架版本如下 spring boot:1.4.3.RELEASE spring framework: 4.3.5.RELEASE hibernate:5.0.1.Final(spring-boot-starter-data-jpa默认依赖) ehcache:2.10.3 项目依赖 <dependency> <groupId>org.springframework.boot</gro

  • 详解Spring boot使用Redis集群替换mybatis二级缓存

    1 . pom.xml添加相关依赖 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.1.RELEASE</version> </parent> <!-- 依赖 --> <dependencies> &l

  • 详解Spring Boot集成MyBatis(注解方式)

    MyBatis是支持定制化SQL.存储过程以及高级映射的优秀的持久层框架,避免了几乎所有的JDBC代码和手动设置参数以及获取结果集.spring Boot是能支持快速创建Spring应用的Java框架.本文通过一个例子来学习Spring Boot如何集成MyBatis,而且过程中不需要XML配置. 创建数据库 本文的例子使用MySQL数据库,首先创建一个用户表,执行sql语句如下: CREATE TABLE IF NOT EXISTS user ( `id` INT(10) NOT NULL A

  • 详解spring Boot 集成 Thymeleaf模板引擎实例

    今天学习了spring boot 集成Thymeleaf模板引擎.发现Thymeleaf功能确实很强大.记录于此,供自己以后使用. Thymeleaf: Thymeleaf是一个java类库,他是一个xml/xhtml/html5的模板引擎,可以作为mvc的web应用的view层. Thymeleaf还提供了额外的模块与Spring MVC集成,所以我们可以使用Thymeleaf完全替代jsp. spring Boot 通过org.springframework.boot.autoconfigu

  • 详解Spring Boot 集成Shiro和CAS

    请大家在看本文之前,先了解如下知识点: 1.Shiro 是什么?怎么用? 2.Cas 是什么?怎么用? 3.最好有spring基础 首先看一下下面这张图: 第一个流程是单纯使用Shiro的流程. 第二个流程是单纯使用Cas的流程. 第三个图是Shiro集成Cas后的流程. PS:流程图急急忙忙画的,整体上应该没有什么问题,具体细节问题还请大家留言指正. 如果你只是打算用到你的Spring Boot项目中,那么看着如下配置完成便可. 如果你想进一步了解其中的细节,还是建议大家单独配置Shiro.单

  • 详解spring boot集成RabbitMQ

    RabbitMQ作为AMQP的代表性产品,在项目中大量使用.结合现在主流的spring boot,极大简化了开发过程中所涉及到的消息通信问题. 首先正确的安装RabbitMQ及运行正常. RabbitMQ需啊erlang环境,所以首先安装对应版本的erlang,可在RabbitMQ官网下载 # rpm -ivh erlang-19.0.4-1.el7.centos.x86_64.rpm 使用yum安装RabbitMQ,避免缺少依赖包引起的安装失败 # yum install rabbitmq-s

  • 详解Spring MVC 集成EHCache缓存

    废话少说,直接上代码: ehcache.xml 文件 <?xml version="1.0" encoding="UTF-8"?> <ehcache dynamicConfig="false" monitoring="off" updateCheck="false" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

  • 详解spring boot jpa整合QueryDSL来简化复杂操作

    前言 使用过spring data jpa的同学,都很清楚,对于复杂的sql查询,处理起来还是比较复杂的,而本文中的QueryDSL就是用来简化JPA操作的. Querydsl定义了一种常用的静态类型语法,用于在持久域模型数据之上进行查询.JDO和JPA是Querydsl的主要集成技术.本文旨在介绍如何使用Querydsl与JPA组合使用.JPA的Querydsl是JPQL和Criteria查询的替代方法.QueryDSL仅仅是一个通用的查询框架,专注于通过Java API构建类型安全的SQL查

  • 详解spring boot rest例子

    简介:本文将帮助您使用 Spring Boot 创建简单的 REST 服务. 你将学习 什么是 REST 服务? 如何使用 Spring Initializr 引导创建 Rest 服务应用程序? 如何创建获取 REST 服务以检索学生注册的课程? 如何为学生注册课程创建 Post REST 服务? 如何利用 postman 执行 rest 服务? 本教程使用的 rest 服务 在本教程中,我们将使用适当的 URI 和 HTTP 方法创建三个服务: @GetMapping("/ students

  • 详解spring boot starter redis配置文件

    spring-boot-starter-Redis主要是通过配置RedisConnectionFactory中的相关参数去实现连接redis service. RedisConnectionFactory是一个接口,有如下4个具体的实现类,我们通常使用的是JedisConnectionFactory. 在spring boot的配置文件中redis的基本配置如下: # Redis服务器地址 spring.redis.host=192.168.0.58 # Redis服务器连接端口 spring.

随机推荐