考虑使用
FactoryBean通过Spring配置文件定义缓存:
<cache:annotation-driven />
<context:component-scan base-package='org.bk.samples.cachexml'></context:component-scan>
<bean id='cacheManager' class='org.springframework.cache.support.SimpleCacheManager'>
<property name='caches'>
<set>
<ref bean='defaultCache'/>
</set>
</property>
</bean>
<bean name='defaultCache' class='org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean'>
<property name='name' value='default'/>
</bean>
工厂bean ConcurrentMapCacheFactoryBean是一个依次负责创建Cache bean的bean。
我第一次尝试将此设置转换为@Configuration样式:
@Bean
public SimpleCacheManager cacheManager(){
SimpleCacheManager cacheManager = new SimpleCacheManager();
List<Cache> caches = new