【发布时间】:2022-08-21 05:18:08
【问题描述】:
我需要你的帮助。我将 Ehcache 3 与 springboot 2 集成在一起。一切都在生产中完美运行。如果我手动执行集成测试(我正在使用 Intellij IDE),集成测试也可以工作。 但是当我运行“mvn install”时,我得到了这个错误:
java.lang.IllegalStateException:无法加载 ApplicationContext 引起:org.springframework.beans.factory.BeanCreationException: 创建类路径中定义的名称为 \'ehCacheManager\' 的 bean 时出错 资源 [com/afklm/belem/payment/config/EhCacheConfiguration.class]: 通过工厂方法实例化 Bean 失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:失败 实例化[org.springframework.cache.CacheManager]:工厂方法 \'ehCacheManager\' 抛出异常;嵌套异常是 javax.cache.CacheException:已经有一个名为 [currenciesCache] 的缓存 存在
CurrencyRepository 接口:
@Repository public interface CurrencyRepository extends JpaRepository<Currency, String> { /** * Gets currencies from Cache. * The real call to the DataBase will be performed if the response is not in cache * * @return list of {@link Currency} */ @Cacheable(cacheNames = \"currenciesCache\", key =\"#root.methodName\", unless = \"#result==null or #result.size()==0\") default List<Currency> getCachedCurrencies() { return findAll(); }缓存配置类
import org.ehcache.config.CacheConfiguration; import org.ehcache.config.builders.CacheConfigurationBuilder; import org.ehcache.config.builders.ExpiryPolicyBuilder; import org.ehcache.config.builders.ResourcePoolsBuilder; import org.ehcache.jsr107.Eh107Configuration; import org.springframework.cache.annotation.CachingConfigurerSupport; import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.jcache.JCacheCacheManager; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.cache.CacheManager; import javax.cache.Caching; import java.time.Duration; import java.util.List; @EnableCaching @Configuration public class EhCacheConfiguration extends CachingConfigurerSupport { @Bean public CacheManager ehCacheManager() { //-> currencies cache configuration CacheConfiguration<String, List> currenciesCacheConfig = CacheConfigurationBuilder .newCacheConfigurationBuilder(String.class, List.class, ResourcePoolsBuilder.heap(1000)) .withExpiry(ExpiryPolicyBuilder.timeToLiveExpiration(Duration.ofDays(30))) .withDefaultEventListenersThreadPool() .build(); javax.cache.CacheManager cacheManager = Caching.getCachingProvider().getCacheManager(); cacheManager.createCache(\"currenciesCache\", Eh107Configuration.fromEhcacheCacheConfiguration(currenciesCacheConfig)); return new JCacheCacheManager(cacheManager); }谢谢你的帮助;我被困住了
-
求救啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊
标签: java spring spring-boot ehcache ehcache-3