sto*_*vik 4 configuration spring caching
要使基于注释的缓存魔法与Spring一起工作,需要在xml中有一个声明,如下所示:
<cache:annotation-driven />
如何以编程方式配置缓存系统?
这就是我所拥有的.我想摆脱@ImportResource
和XML文件.
@Configuration
@ImportResource("classpath:cache-context.xml")
public class DI_EhCache {
/**
* Create cache object for various cachable methods and add to EhCache Manager.
*
* @return EhCacheManager
*/
@Bean
EhCacheCacheManager cacheManager() {
EhCacheCacheManager ehcm = new EhCacheCacheManager();
CacheManager cm = CacheManager.create();
Cache station = new Cache("station", 1, false, true, 0, 10);
cm.addCache(station);
ehcm.setCacheManager(cm);
return ehcm;
}
}
Run Code Online (Sandbox Code Playgroud)
Spring 3.1 RC2添加了@EnableCaching
注释,RC1中没有.此注释相当于<cache:annotation-driven />
并添加到您的@Configuration
类中:
@Configuration
@EnableCaching
public class DI_EhCache {
Run Code Online (Sandbox Code Playgroud)
RC2似乎并没有被公布,并且该文档不从网站链接的,但你可以下载它在这里,看文档的@EnableCaching
位置.
归档时间: |
|
查看次数: |
2761 次 |
最近记录: |