Spring Java 注解配置之 Ehcache配置

Spring使用Ehcache缓存机制

@Configuration
public class SpringCacheEhcacheConfig {

    /**
     * 缓存配置
     * @return
     */
    @Bean("cacheManagerFactoryBean")
    public EhCacheManagerFactoryBean cacheManagerFactoryBean() {
        EhCacheManagerFactoryBean factoryBean = new EhCacheManagerFactoryBean();
        factoryBean.setConfigLocation(new ClassPathResource("spring_cache.xml"));
        factoryBean.setShared(true);

        return factoryBean;
    }

    /**
     * 缓存管理器
     * @return
     */
    @Bean("springCacheManager")
    public EhCacheCacheManager ehCacheCacheManager(@Qualifier("cacheManagerFactoryBean") CacheManager cacheManager) {
        return new EhCacheCacheManager(cacheManager);
    }

}

需要在src/main/resources 下建立spring_cache.xml配置文件,其配置方式在ehcache官方文档中可以了解到,我的配置比较简单,就配置了shrio使用的缓存




    
    
        
    

    

    

    

你可能感兴趣的:(Spring Java 注解配置之 Ehcache配置)