Spring Java 注解配置之 Ehcache3.+配置

Spring使用Ehcache3.+缓存机制

@Configuration
@EnableSpringHttpSession
public class SpringCacheEhcacheConfig {

    /**
     * 缓存配置
     * 
     * @return
     * @throws IOException
     */
    @Bean("mManagerFactoryBean")
    public JCacheManagerFactoryBean mManagerFactoryBean() throws IOException {
        JCacheManagerFactoryBean factoryBean = new JCacheManagerFactoryBean();
        factoryBean.setCacheManagerUri(new ClassPathResource("ehcache.xml").getURI());

        return factoryBean;
    }

    /**
     * 缓存管理器
     * 
     * @return
     */
    @Bean("springCacheManager")
    public JCacheCacheManager mCacheManager(@Qualifier("mManagerFactoryBean") CacheManager cacheManager) {
        return new JCacheCacheManager(cacheManager);
    }

    /**
     * Spring Session
     * 
     * @return
     */
    @Bean
    public JCacheCacheSessionRepository mSessionRepository(@Qualifier("mManagerFactoryBean") CacheManager cacheManager) {
        return new JCacheCacheSessionRepository(cacheManager);
    }

}

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



    

    
        java.lang.String
        cn.virens.web.components.session.CacheSession
        
            30
        
    

    
        
            30
        
    

    
        
            30
        
    

    
        
            60
        
    
    
        
            60
        
    
    
        
            60
        
    
    
    
        
            50
            2000
            500
        
    

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