备忘 springboot 整合ehcache,注入CacheManager时提示 required a bean of type 'org.springframework.cache.Ca
问题因人而异,此处仅做备忘
整合过程:
1、添加maven依赖
<dependency> <groupId>net.sf.ehcachegroupId> <artifactId>ehcacheartifactId> <version>2.10.6version> dependency>
2、开启springboot缓存
@EnableCaching @SpringBootApplication public class EhcachetestApplication { public static void main(String[] args) { SpringApplication.run(EhcachetestApplication.class, args); } }
3、在使用位置注入 org.springframework.cache.CacheManager
注:上面飘红并不是报错的原因,可忽略。
4、打包测试,报 required a bean of type 'org.springframework.cache.CacheManager' that could not be found
5、增加 spring-boot-starter-cache 依赖
<dependency> <groupId>org.springframework.bootgroupId> <artifactId>spring-boot-starter-cacheartifactId> dependency>
6、再次打包测试,一切OK
问题原因分析:
spring-boot-starter-cache 是springboot缓存功能的依赖,如果要开启springboot cache必需添加该依赖。这次因为这个地方忽视,造成调错花费了不少时间,记录下来加深记忆!