我有一個問題,實施一個二流緩存管理器。目前我正在使用EhCache,它工作正常。另外我想實現Java簡單緩存。春季:多個高速緩存管理器
我CacheConfiguration看起來是這樣的:
CacheConfiguration.java
@Configuration
@EnableCaching
@AutoConfigureAfter(value = { MetricsConfiguration.class })
@AutoConfigureBefore(value = { WebConfigurer.class, DatabaseConfiguration.class })
public class CacheConfiguration {
private final javax.cache.configuration.Configuration<Object, Object> jcacheConfiguration;
public CacheConfiguration(JHipsterProperties jHipsterProperties) {
JHipsterProperties.Cache.Ehcache ehcache =
jHipsterProperties.getCache().getEhcache();
jcacheConfiguration = Eh107Configuration.fromEhcacheCacheConfiguration(
CacheConfigurationBuilder.newCacheConfigurationBuilder(Object.class, Object.class,
ResourcePoolsBuilder.heap(ehcache.getMaxEntries()))
.withExpiry(Expirations.timeToLiveExpiration(Duration.of(ehcache.getTimeToLiveSeconds(), TimeUnit.SECONDS)))
.build());
}
/**
* EhCache configuration
*
* @return
*/
@Bean
@Primary
public JCacheManagerCustomizer cacheManagerCustomizer() {
return cm -> {
cm.createCache(com.david.coinlender.domain.News.class.getName(), jcacheConfiguration);
// ...More caches
}
/**
* Java Simple Cache configuration
* @return
*/
@Bean
@Qualifier("simpleCacheManager")
public CacheManager simpleCacheManager() {
SimpleCacheManager simpleCacheManager = new SimpleCacheManager();
simpleCacheManager.setCaches(Arrays.asList(new ConcurrentMapCache("bitfinexAuthCache")));
return simpleCacheManager;
}
}
用簡單的緩存我想緩存的對象。即:
@Cacheable(cacheManager = "simpleCacheManager", cacheNames = "bitfinexAuthCache", key = "#apiKey.apiKey")
private Exchange createBitfinexAuthenticatedExchange(ApiKeys apiKey) {
ExchangeSpecification exSpec = new BitfinexExchange().getDefaultExchangeSpecification();
exSpec.setApiKey(apiKey.getApiKey());
exSpec.setSecretKey(apiKey.getSecret());
Exchange bfx = ExchangeFactory.INSTANCE.createExchange(BitfinexExchange.class.getName());
bfx.applySpecification(exSpec);
return bfx;
}
然而,在服務器啓動時liquibase給我一個錯誤,指出:
Caused by: java.lang.IllegalStateException: All Hibernate caches should be created upfront. Please update CacheConfiguration.java to add com.david.coinlender.domain.News
at io.github.jhipster.config.jcache.NoDefaultJCacheRegionFactory.createCache(NoDefaultJCacheRegionFactory.java:37)
at org.hibernate.cache.jcache.JCacheRegionFactory.getOrCreateCache(JCacheRegionFactory.java:190)
at org.hibernate.cache.jcache.JCacheRegionFactory.buildEntityRegion(JCacheRegionFactory.java:113)
at org.hibernate.cache.spi.RegionFactory.buildEntityRegion(RegionFactory.java:132)
at org.hibernate.internal.CacheImpl.determineEntityRegionAccessStrategy(CacheImpl.java:439)
at org.hibernate.metamodel.internal.MetamodelImpl.initialize(MetamodelImpl.java:120)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:297)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:445)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:889)
... 25 common frames omitted
我用我的器件的應用框架Jhipster。我現在將這個問題搜索了幾個小時,還沒有找到解決方案。
由於配置錯誤導致此錯誤?有人可以請指點我正確的方向嗎?
嘗試'@Bean( 「simpleCacheManager」)'代替'@ Qualifier' –
不幸的是拋出了同樣的錯誤:/ – dave0688