Created
April 23, 2014 18:22
-
-
Save andresteingress/11226958 to your computer and use it in GitHub Desktop.
ConditionalOnExpression - A conditional EhCache manager configuration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
@EnableCaching | |
@ConditionalOnExpression("${spring.cacheable.cache}") | |
public class EhCacheConfiguration { | |
@Autowired | |
private net.sf.ehcache.CacheManager cacheManager; | |
@Bean(name = "cacheManager") | |
public CacheManager ehCacheCacheManager() | |
{ | |
return new EhCacheCacheManager(cacheManager); | |
} | |
@Bean | |
public EhCacheManagerFactoryBean ehcache() { | |
EhCacheManagerFactoryBean ehCacheManagerFactoryBean = new EhCacheManagerFactoryBean(); | |
ehCacheManagerFactoryBean.setConfigLocation(new ClassPathResource("ehcache.xml")); | |
// the cache manager should only be created once, so this must be shared == true | |
ehCacheManagerFactoryBean.setShared(true); | |
return ehCacheManagerFactoryBean; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the cache manager creation can therefore be controlled by the application property
spring.cacheable.cache
.