今天在项目中集成redis,看了一个文章springboot集成redis (Lettuce),然后我在集成的时候到了一个问题
Description:
Parameter 1 of method securityManager in com.fc.sayhi.shiro.config.ShiroConfig required a bean of type 'org.apache.shiro.cache.CacheManager' that could not be found.
Action:
Consider defining a bean of type 'org.apache.shiro.cache.CacheManager' in your configuration.
刚开始遇到这个问题还有些懵逼,我就去我的ShiroConfig文件中去查看,一看发现我之前写了CacheManager
/**
* 缓存配置
* @return
*/
@Bean
public CacheManager cacheManager() {
MemoryConstrainedCacheManager cacheManager=new MemoryConstrainedCacheManager();//使用内存缓存
return cacheManager;
}
然而我的RedisConfig上面用了@EnableCaching导致启动失败
@EnableCaching
@EnableCaching注解是spring framework中的注解驱动的缓存管理功能。自spring版本3.1起加入了该注解。如果你使用了这个注解,那么你就不需要在XML文件中配置cache manager了。
当你在配置类(@Configuration)上使用@EnableCaching注解时,会触发一个post processor,这会扫描每一个spring bean,查看是否已经存在注解对应的缓存。如果找到了,就会自动创建一个代理拦截方法调用,使用缓存的bean执行处理
去掉注解解决问题