我正在尝试将缓存添加到springboot应用程序,并且我遇到了在启动期间抛出org.ehcache.jsr107.MultiCacheException异常的问题.
我使用以下(全部通过Maven pom文件加载):Springboot 1.5.5,Ehcache 3.3.1,Javax缓存1.0.0
我的SpringBootApplication看起来像这样:
@SpringBootApplication
@EnableCaching
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个包含以下内容的CacheConfig类:
@Component
public class CacheConfig implements JCacheManagerCustomizer{
@Override
public void customize(javax.cache.CacheManager cacheManager) {
cacheManager.createCache("item", new MutableConfiguration<>()
.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MINUTES, 5)))
.setStoreByValue(false)
.setStatisticsEnabled(true));
}
}
Run Code Online (Sandbox Code Playgroud)
我的ehcache.xml文件包含:
<config
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns='http://www.ehcache.org/v3'
xmlns:jsr107='http://www.ehcache.org/v3/jsr107'>
<service>
<jsr107:defaults>
<jsr107:cache name="item" template="heap-cache"/>
</jsr107:defaults>
</service>
<cache-template name="heap-cache">
<listeners>
<listener>
<class>org.terracotta.ehcache.EventLogger</class>
<event-firing-mode>ASYNCHRONOUS</event-firing-mode>
<event-ordering-mode>UNORDERED</event-ordering-mode>
<events-to-fire-on>CREATED</events-to-fire-on>
<events-to-fire-on>UPDATED</events-to-fire-on>
<events-to-fire-on>EXPIRED</events-to-fire-on>
<events-to-fire-on>REMOVED</events-to-fire-on>
<events-to-fire-on>EVICTED</events-to-fire-on>
</listener>
</listeners>
<resources>
<heap unit="entries">2000</heap>
<offheap unit="MB">100</offheap>
</resources>
</cache-template>
</config>
Run Code Online (Sandbox Code Playgroud)
测试项服务包含: …