2011-12-07 53 views
4

要獲得基於註釋的緩存魔法與Spring的工作,一是需要有一個XML格式的聲明,就像這樣: <cache:annotation-driven />非XML版本<緩存:註解驅動/>

哪有我以編程方式配置緩存系統?

這就是我所擁有的。我想擺脫@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; 
    } 
} 

回答

8

Spring 3.1 RC2添加了@EnableCaching註釋,該註釋在RC1中不存在。此註釋的<cache:annotation-driven />等效,並添加到您的@Configuration類:

@Configuration 
@EnableCaching 
public class DI_EhCache { 

器Rc2似乎並沒有被公佈,並且該文檔不從網站鏈接的,但你可以下載它here ,並查看@EnableCachinghere的文檔。

相關問題