Springboot整合集成ehcache3
2017-12-13 15:10
381 查看
1.pom.xml中添加依赖。spring-boot-starer-cache中已经有了ehcache和cache-api,可以不用再添加。
<!-- 本地缓存依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<!--
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
<dependency>
<groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId>
</dependency>
-->
2. application.properties文件中添加配置位置。指定使用的cacheManger是jcache。
#-------------------ehcache----------------------
spring.cache.jcache.config=classpath:/config/ehcache.xml
3. 在配置的目录中新建添加ecache.xml文件。更详细的可以参照官方文档
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.ehcache.org/v3"
xmlns:jsr107="http://www.ehcache.org/v3/jsr107"
xsi:schemaLocation="http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.2.xsd http://www.ehcache.org/v3/jsr107 http://www.ehcache.org/schema/ehcache-107-ext-3.2.xsd">
<persistence directory="java.io.tmpdir"/>
<cache-template name="default">
<resources>
<heap unit="entries">2000</heap>
<offheap unit="MB">100</offheap>
</resources>
</cache-template>
<cache alias="SSAccountInfo" uses-template="default">
<expiry>
<ttl unit="seconds">600</ttl>
</expiry>
</cache>
</config>
3.在配置类或者启动类上面,添加启用缓存的注解
@EnableCaching
4 . 在需要缓存的数据方法上面打上缓存注解。几个常用的缓存注解可参照官网。
package com.caiwufei.module.cfsss.dao;
import org.springframework.cache.annotation.Cacheable;
import com.caiwufei.entity.base.BaseMapper;
import com.caiwufei.entity.cfsss.SSAccountInfo;
public interface SSAccountInfoDao extends BaseMapper<SSAccountInfo>{
@Cacheable(cacheNames="SSAccountInfo", unless="#result==null")
public SSAccountInfo queryAccountInfoById(SSAccountInfo a);
}
<!-- 本地缓存依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<!--
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
<dependency>
<groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId>
</dependency>
-->
2. application.properties文件中添加配置位置。指定使用的cacheManger是jcache。
#-------------------ehcache----------------------
spring.cache.jcache.config=classpath:/config/ehcache.xml
3. 在配置的目录中新建添加ecache.xml文件。更详细的可以参照官方文档
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.ehcache.org/v3"
xmlns:jsr107="http://www.ehcache.org/v3/jsr107"
xsi:schemaLocation="http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.2.xsd http://www.ehcache.org/v3/jsr107 http://www.ehcache.org/schema/ehcache-107-ext-3.2.xsd">
<persistence directory="java.io.tmpdir"/>
<cache-template name="default">
<resources>
<heap unit="entries">2000</heap>
<offheap unit="MB">100</offheap>
</resources>
</cache-template>
<cache alias="SSAccountInfo" uses-template="default">
<expiry>
<ttl unit="seconds">600</ttl>
</expiry>
</cache>
</config>
3.在配置类或者启动类上面,添加启用缓存的注解
@EnableCaching
4 . 在需要缓存的数据方法上面打上缓存注解。几个常用的缓存注解可参照官网。
package com.caiwufei.module.cfsss.dao;
import org.springframework.cache.annotation.Cacheable;
import com.caiwufei.entity.base.BaseMapper;
import com.caiwufei.entity.cfsss.SSAccountInfo;
public interface SSAccountInfoDao extends BaseMapper<SSAccountInfo>{
@Cacheable(cacheNames="SSAccountInfo", unless="#result==null")
public SSAccountInfo queryAccountInfoById(SSAccountInfo a);
}
相关文章推荐
- springboot同时整合redis和ehcache
- Spring-Boot (四) cache/ehcache/redis-cache集成使用
- Spring Boot整合ehcache3.0 缓存
- 37. Spring Boot集成EHCache实现缓存机制【从零开始学Spring Boot】
- SpringBoot集成ehcache
- spring-boot整合ehcache实现缓存机制的方法
- spring boot spring cache ehcache3.x整合
- SpringBoot整合集成redis
- IntelliJ IDEA Spring Boot(6) 集成Hibernate+Shiro+Ehcache
- spring-boot整合ehcache实现缓存机制
- 【spring-boot】spring-boot集成ehcache实现缓存机制
- Springboot集成ehcache时获取CacheManager自定义添加其他缓存
- springboot整合ehcache 实现支付超时限制的方法
- 【spring-boot】spring-boot整合ehcache实现缓存机制
- SpringBoot 集成Ehcache实现缓存
- spring-boot整合ehcache实现缓存机制
- 详解Springboot整合Dubbo之代码集成和发布
- 【转载】Springboot整合 一 集成 redis
- Spring Boot整合集成StringRedisTemplate的简单记录
- Spring Boot---(14)Spring Boot 整合EhCache做缓存