当前在我的xml配置中,cacheManager正在以以下方式创建:
<bean id="cacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:ehcache-config.xml"/>
<property name="shared" value="true"/>
</bean>
<bean id="cacheManager"
class="org.springframework.cache.ehcache.EhCacheCacheManager">
<property name="cacheManager" ref="cacheManagerFactory"/>
</bean>
但是现在我需要使用tomcat目录中的cache-config
文件,而我能够处理此问题的唯一方法是以另一种方式使用java config:
@Bean
public EhCacheManagerFactoryBean cacheManagerFactory() {
EhCacheManagerFactoryBean result = new EhCacheManagerFactoryBean();
result.setCacheManagerName("cacheManager");
result.setShared(true);
result.setConfigLocation(
new UrlResource(
SlsConfiguration.class.getClassLoader().getResource("EHCacheConfig/ehcache_config.xml")
)
);
return result;
}
@Bean
public EhCacheCacheManager cacheManager() {
EhCacheCacheManager result = new EhCacheCacheManager();
result.setCacheManager(cacheManagerFactory().getObject());
return result;
}
是否可以使用xml config归档相同的结果?