spring 带有 ehcache 的启动缓存找不到 Builder 名为 xxx 的缓存
spring boot cache with ehcache Cannot find cache named xxx for Builder
我在为带有 spring 引导和 spring 缓存启动器的 ehcache 使用 java 配置时遇到错误
找不到名为 'bpConfigs' 的缓存用于 Builder[public java.util.List com.xxx.bp.repository.BpConfigRepository.getEligibleConfig()] caches=[bpConfigs] |键='' | keyGenerator='' |缓存管理器='' |缓存解析器='' |条件='' |除非='' |同步='false'
我的配置:
@EnableCaching
@Configuration
public class CachingConfig implements CachingConfigurer {
private static final int MAX_ENTRIES = 1000;
private static final int LIVE_IN_SEC = 10 * 60;
@Bean
public net.sf.ehcache.CacheManager ehCacheManager() {
net.sf.ehcache.config.Configuration config = new Configuration();
config.addCache(createBpConfigsCache());
return net.sf.ehcache.CacheManager.newInstance(config);
}
@Bean
@Override
public CacheManager cacheManager() {
return new EhCacheCacheManager(ehCacheManager());
}
@Bean
@Override
public CacheResolver cacheResolver() {
return new SimpleCacheResolver(cacheManager());
}
@Bean
@Override
public KeyGenerator keyGenerator() {
return new SimpleKeyGenerator();
}
@Bean
@Override
public CacheErrorHandler errorHandler() {
return new SimpleCacheErrorHandler();
}
private CacheConfiguration createBpConfigsCache() {
CacheConfiguration cfg = new CacheConfiguration();
cfg.setName("bpConfigs");
cfg.setMemoryStoreEvictionPolicy("LRU");
cfg.setTransactionalMode("OFF");
cfg.setEternal(false);
cfg.setTimeToLiveSeconds(LIVE_IN_SEC);
cfg.setMaxEntriesLocalHeap(MAX_ENTRIES);
return cfg;
}
}
我的方法:
@Repository
@CacheConfig(cacheNames ="bpConfigs")
public class BphConfigRepository {
@Cacheable
public List<LoyaltyEli> getbPConfig() {
return jdbcTemplate.query("select XXX,YYY from TABLE", new myMapper());
}
}
我刚刚删除了已实现的接口 CachingConfigurer,现在可以了。
@EnableCaching
@Configuration("CachingConfig")
public class CachingConfig {
}
我在为带有 spring 引导和 spring 缓存启动器的 ehcache 使用 java 配置时遇到错误 找不到名为 'bpConfigs' 的缓存用于 Builder[public java.util.List com.xxx.bp.repository.BpConfigRepository.getEligibleConfig()] caches=[bpConfigs] |键='' | keyGenerator='' |缓存管理器='' |缓存解析器='' |条件='' |除非='' |同步='false'
我的配置:
@EnableCaching
@Configuration
public class CachingConfig implements CachingConfigurer {
private static final int MAX_ENTRIES = 1000;
private static final int LIVE_IN_SEC = 10 * 60;
@Bean
public net.sf.ehcache.CacheManager ehCacheManager() {
net.sf.ehcache.config.Configuration config = new Configuration();
config.addCache(createBpConfigsCache());
return net.sf.ehcache.CacheManager.newInstance(config);
}
@Bean
@Override
public CacheManager cacheManager() {
return new EhCacheCacheManager(ehCacheManager());
}
@Bean
@Override
public CacheResolver cacheResolver() {
return new SimpleCacheResolver(cacheManager());
}
@Bean
@Override
public KeyGenerator keyGenerator() {
return new SimpleKeyGenerator();
}
@Bean
@Override
public CacheErrorHandler errorHandler() {
return new SimpleCacheErrorHandler();
}
private CacheConfiguration createBpConfigsCache() {
CacheConfiguration cfg = new CacheConfiguration();
cfg.setName("bpConfigs");
cfg.setMemoryStoreEvictionPolicy("LRU");
cfg.setTransactionalMode("OFF");
cfg.setEternal(false);
cfg.setTimeToLiveSeconds(LIVE_IN_SEC);
cfg.setMaxEntriesLocalHeap(MAX_ENTRIES);
return cfg;
}
}
我的方法:
@Repository
@CacheConfig(cacheNames ="bpConfigs")
public class BphConfigRepository {
@Cacheable
public List<LoyaltyEli> getbPConfig() {
return jdbcTemplate.query("select XXX,YYY from TABLE", new myMapper());
}
}
我刚刚删除了已实现的接口 CachingConfigurer,现在可以了。
@EnableCaching
@Configuration("CachingConfig")
public class CachingConfig {
}