我尝试将我的ehcache xml转换为Java Config。我有以下代码。
@Bean
public EhCacheManagerFactoryBean ehCache(){
EhCacheManagerFactoryBean ehCache = new EhCacheManagerFactoryBean();
ehCache.setConfigLocation(new ClassPathResource("ehcache.xml"));
ehCache.setShared(true);
ehCache.setCacheManagerName("CACHE_MANAGER");
return ehCache;
}
@Bean
public CacheManager cacheManager(){
EhCacheCacheManager cacheManager = new EhCacheCacheManager();
cacheManager.setCacheManager(ehCache().getObject());
return cacheManager;
}
我收到以下错误:
Caused by: java.lang.ClassCastException: net.sf.ehcache.CacheManager cannot be cast to org.springframework.cache.ehcache.EhCacheManagerFactoryBean
我对ehcache的依赖是
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>2.6.3</version>
</dependency>
当我执行以下操作时,错误消失了:
private EhCacheManagerFactoryBean ehCache;
@Bean
public EhCacheManagerFactoryBean ehCache(){
ehCache = new EhCacheManagerFactoryBean();
ehCache.setConfigLocation(new ClassPathResource("ehcache.xml"));
ehCache.setShared(true);
ehCache.setCacheManagerName("CACHE_MANAGER");
return ehCache;
}
@Bean
public CacheManager cacheManager(){
EhCacheCacheManager cacheManager = new EhCacheCacheManager();
cacheManager.setCacheManager(ehCache.getObject());
return cacheManager;
}
这是春天的错误还是我做错了什么?谢谢。
答案 0 :(得分:0)
可能是侥幸。我重新启动了我的想法,它不再抱怨这个问题。