Springboot2.x 整合 Ehcache3.x遇到的坑
Springboot整合Ehcache网上已经有一大堆文章,这里主要记录下整合Ehcache3.X版本遇到的坑,就是springboot整合3.X版本是借助JCache (JSR-107)规范来实现。即 Ehcache3.X实现了JSR-107规范,所以配置和依赖中一定要引入相应包和使用相应jcache配置!
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-cache</artifactId> </dependency> <dependency> <groupId>org.ehcache</groupId> <artifactId>ehcache</artifactId> </dependency> <!-- 这里一定要引入cache-api包,否则无法启用JCache配置 --> <dependency> <groupId>javax.cache</groupId> <artifactId>cache-api</artifactId> </dependency>
配置时注意使用jcahe而不是echache:
spring: cache: # ehcache: 注意ehcache2.X版本才使用该配置 jcache: config: classpath:ehcache.xml