java - 带有ehcache的spring boot缓存找不到Builder的名为xxx的缓存
问题描述
我在使用带有spring boot和spring cache starter的ehcache的java配置时遇到错误找不到Builder [public java.util.List com.xxx.bp.repository.BpConfigRepository.getEligibleConfig()]缓存的名为'bpConfigs'的缓存=[bpConfigs] | 键='' | 密钥生成器='' | 缓存管理器='' | 缓存解析器='' | 条件='' | 除非='' | 同步='假'
我的配置:
@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 {
}
推荐阅读
- reactjs - 开发时带有 CKEditor 5 / CKFinder CORS 的 ReactJS 问题
- react-native - 如何在没有互联网的情况下调试本机应用程序?
- sikuli - 错误后重新启动 Sikuli 脚本 - 从命令行调用
- python - 如何制作仅对基础文件的一部分进行操作的文件对象?
- javascript - 在树状图中输入、更新和退出选择
- python - 我需要做什么来翻译这份清单?
- java - Android Studio:将字符串从 HashMap 转换为 Uri 后尝试播放音频时出现 java.io.FileNotFoundException
- sql - 无法让 select 语句在子程序中工作
- json - 如何使用 json 文件中列出的本地路径导入图像?
- angular - Angular 实时开发服务器适用于 Firefox,但不适用于 chrome