IllegalStateException:未找到持久资源的服务:磁盘 [ehCache 3]
IllegalStateException: No service found for persistable resource: disk [ehCache 3]
我想在应用程序重启后使缓存可用,并在配置中添加了以下行:
<disk unit="MB">100</disk>
启动应用程序后,我有以下堆栈跟踪:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheManager' defined in class path resource [my/pack/EhcacheConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cache.CacheManager]: Factory method 'cacheManager' threw exception; nested exception is org.ehcache.StateTransitionException: Cache 'pow_cache' creation in EhcacheManager failed.
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:456) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean[=11=](AbstractBeanFactory.java:320) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:845) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:742) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:389) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:311) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1213) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1202) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at my.pack.Main.main(Main.java:12) ~[main/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cache.CacheManager]: Factory method 'cacheManager' threw exception; nested exception is org.ehcache.StateTransitionException: Cache 'pow_cache' creation in EhcacheManager failed.
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
... 18 common frames omitted
Caused by: org.ehcache.StateTransitionException: Cache 'pow_cache' creation in EhcacheManager failed.
at org.ehcache.core.StatusTransitioner$Transition.failed(StatusTransitioner.java:235) ~[ehcache-3.6.3.jar:3.6.3 03c2e612075c4e06bc994817543ab7512486b689]
at org.ehcache.core.EhcacheManager.init(EhcacheManager.java:603) ~[ehcache-3.6.3.jar:3.6.3 03c2e612075c4e06bc994817543ab7512486b689]
at org.ehcache.jsr107.EhcacheCachingProvider.createCacheManager(EhcacheCachingProvider.java:155) ~[ehcache-3.6.3.jar:3.6.3 03c2e612075c4e06bc994817543ab7512486b689]
at org.ehcache.jsr107.EhcacheCachingProvider.getCacheManager(EhcacheCachingProvider.java:131) ~[ehcache-3.6.3.jar:3.6.3 03c2e612075c4e06bc994817543ab7512486b689]
at org.ehcache.jsr107.EhcacheCachingProvider.getCacheManager(EhcacheCachingProvider.java:82) ~[ehcache-3.6.3.jar:3.6.3 03c2e612075c4e06bc994817543ab7512486b689]
at org.ehcache.jsr107.EhcacheCachingProvider.getCacheManager(EhcacheCachingProvider.java:190) ~[ehcache-3.6.3.jar:3.6.3 03c2e612075c4e06bc994817543ab7512486b689]
at my.pack.EhcacheConfig.cacheManager(EhcacheConfig.java:19) ~[main/:na]
at my.pack.EhcacheConfig$$EnhancerBySpringCGLIB$11178.CGLIB$cacheManager[=11=](<generated>) ~[main/:na]
at my.pack.EhcacheConfig$$EnhancerBySpringCGLIB$11178$$FastClassBySpringCGLIB$c04d8c0.invoke(<generated>) ~[main/:na]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at my.pack.EhcacheConfig$$EnhancerBySpringCGLIB$11178.cacheManager(<generated>) ~[main/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
... 19 common frames omitted
Caused by: java.lang.IllegalStateException: Cache 'pow_cache' creation in EhcacheManager failed.
at org.ehcache.core.EhcacheManager.createCache(EhcacheManager.java:294) ~[ehcache-3.6.3.jar:3.6.3 03c2e612075c4e06bc994817543ab7512486b689]
at org.ehcache.core.EhcacheManager.init(EhcacheManager.java:582) ~[ehcache-3.6.3.jar:3.6.3 03c2e612075c4e06bc994817543ab7512486b689]
... 34 common frames omitted
Caused by: java.lang.IllegalStateException: No service found for persistable resource: disk
at org.ehcache.core.EhcacheManager.getPersistableResourceService(EhcacheManager.java:533) ~[ehcache-3.6.3.jar:3.6.3 03c2e612075c4e06bc994817543ab7512486b689]
at org.ehcache.core.EhcacheManager.getStore(EhcacheManager.java:435) ~[ehcache-3.6.3.jar:3.6.3 03c2e612075c4e06bc994817543ab7512486b689]
at org.ehcache.core.EhcacheManager.createNewEhcache(EhcacheManager.java:317) ~[ehcache-3.6.3.jar:3.6.3 03c2e612075c4e06bc994817543ab7512486b689]
at org.ehcache.core.EhcacheManager.createCache(EhcacheManager.java:266) ~[ehcache-3.6.3.jar:3.6.3 03c2e612075c4e06bc994817543ab7512486b689]
... 35 common frames omitted
ehcache 配置:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.ehcache.org/v3"
xmlns:jsr107="http://www.ehcache.org/v3/jsr107"
xsi:schemaLocation="
http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.0.xsd
http://www.ehcache.org/v3/jsr107 http://www.ehcache.org/schema/ehcache-107-ext-3.0.xsd">
<cache alias="pow_cache">
<key-type>org.springframework.cache.interceptor.SimpleKey</key-type>
<value-type>java.lang.Double</value-type>
<expiry>
<ttl unit="seconds">120</ttl>
</expiry>
<listeners>
<listener>
<class>my.pack.CacheEventLogger</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>EXPIRED</events-to-fire-on>
</listener>
</listeners>
<resources>
<heap unit="entries">2</heap>
<offheap unit="MB">10</offheap>
<disk unit="MB">100</disk>
</resources>
</cache>
</config>
spring 配置:
@Configuration
@EnableCaching
public class EhcacheConfig {
@Bean
public CacheManager cacheManager() throws URISyntaxException {
JCacheCacheManager jCacheCacheManager = new JCacheCacheManager(Caching.getCachingProvider().getCacheManager(
getClass().getResource("/ehcache.xml").toURI(),
getClass().getClassLoader()
));
javax.cache.CacheManager cacheManager = jCacheCacheManager.getCacheManager();
Cache<Object, Object> powCache = cacheManager.getCache("pow_cache");
return jCacheCacheManager;
}
}
spring 引导版本为 2.1.6.RELEASE
ehcache 版本是 3.6.3
我做错了什么?如何纠正?
P.S.
我想我需要提及磁盘上缓存的文件位置,但我不知道在哪里。
我添加了
<persistence directory="spring-boot-ehcache/cache" />
在 <cache>
标记和堆栈跟踪消失之前
我想在应用程序重启后使缓存可用,并在配置中添加了以下行:
<disk unit="MB">100</disk>
启动应用程序后,我有以下堆栈跟踪:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheManager' defined in class path resource [my/pack/EhcacheConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cache.CacheManager]: Factory method 'cacheManager' threw exception; nested exception is org.ehcache.StateTransitionException: Cache 'pow_cache' creation in EhcacheManager failed.
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:456) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean[=11=](AbstractBeanFactory.java:320) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:845) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:742) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:389) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:311) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1213) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1202) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at my.pack.Main.main(Main.java:12) ~[main/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cache.CacheManager]: Factory method 'cacheManager' threw exception; nested exception is org.ehcache.StateTransitionException: Cache 'pow_cache' creation in EhcacheManager failed.
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
... 18 common frames omitted
Caused by: org.ehcache.StateTransitionException: Cache 'pow_cache' creation in EhcacheManager failed.
at org.ehcache.core.StatusTransitioner$Transition.failed(StatusTransitioner.java:235) ~[ehcache-3.6.3.jar:3.6.3 03c2e612075c4e06bc994817543ab7512486b689]
at org.ehcache.core.EhcacheManager.init(EhcacheManager.java:603) ~[ehcache-3.6.3.jar:3.6.3 03c2e612075c4e06bc994817543ab7512486b689]
at org.ehcache.jsr107.EhcacheCachingProvider.createCacheManager(EhcacheCachingProvider.java:155) ~[ehcache-3.6.3.jar:3.6.3 03c2e612075c4e06bc994817543ab7512486b689]
at org.ehcache.jsr107.EhcacheCachingProvider.getCacheManager(EhcacheCachingProvider.java:131) ~[ehcache-3.6.3.jar:3.6.3 03c2e612075c4e06bc994817543ab7512486b689]
at org.ehcache.jsr107.EhcacheCachingProvider.getCacheManager(EhcacheCachingProvider.java:82) ~[ehcache-3.6.3.jar:3.6.3 03c2e612075c4e06bc994817543ab7512486b689]
at org.ehcache.jsr107.EhcacheCachingProvider.getCacheManager(EhcacheCachingProvider.java:190) ~[ehcache-3.6.3.jar:3.6.3 03c2e612075c4e06bc994817543ab7512486b689]
at my.pack.EhcacheConfig.cacheManager(EhcacheConfig.java:19) ~[main/:na]
at my.pack.EhcacheConfig$$EnhancerBySpringCGLIB$11178.CGLIB$cacheManager[=11=](<generated>) ~[main/:na]
at my.pack.EhcacheConfig$$EnhancerBySpringCGLIB$11178$$FastClassBySpringCGLIB$c04d8c0.invoke(<generated>) ~[main/:na]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at my.pack.EhcacheConfig$$EnhancerBySpringCGLIB$11178.cacheManager(<generated>) ~[main/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
... 19 common frames omitted
Caused by: java.lang.IllegalStateException: Cache 'pow_cache' creation in EhcacheManager failed.
at org.ehcache.core.EhcacheManager.createCache(EhcacheManager.java:294) ~[ehcache-3.6.3.jar:3.6.3 03c2e612075c4e06bc994817543ab7512486b689]
at org.ehcache.core.EhcacheManager.init(EhcacheManager.java:582) ~[ehcache-3.6.3.jar:3.6.3 03c2e612075c4e06bc994817543ab7512486b689]
... 34 common frames omitted
Caused by: java.lang.IllegalStateException: No service found for persistable resource: disk
at org.ehcache.core.EhcacheManager.getPersistableResourceService(EhcacheManager.java:533) ~[ehcache-3.6.3.jar:3.6.3 03c2e612075c4e06bc994817543ab7512486b689]
at org.ehcache.core.EhcacheManager.getStore(EhcacheManager.java:435) ~[ehcache-3.6.3.jar:3.6.3 03c2e612075c4e06bc994817543ab7512486b689]
at org.ehcache.core.EhcacheManager.createNewEhcache(EhcacheManager.java:317) ~[ehcache-3.6.3.jar:3.6.3 03c2e612075c4e06bc994817543ab7512486b689]
at org.ehcache.core.EhcacheManager.createCache(EhcacheManager.java:266) ~[ehcache-3.6.3.jar:3.6.3 03c2e612075c4e06bc994817543ab7512486b689]
... 35 common frames omitted
ehcache 配置:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.ehcache.org/v3"
xmlns:jsr107="http://www.ehcache.org/v3/jsr107"
xsi:schemaLocation="
http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.0.xsd
http://www.ehcache.org/v3/jsr107 http://www.ehcache.org/schema/ehcache-107-ext-3.0.xsd">
<cache alias="pow_cache">
<key-type>org.springframework.cache.interceptor.SimpleKey</key-type>
<value-type>java.lang.Double</value-type>
<expiry>
<ttl unit="seconds">120</ttl>
</expiry>
<listeners>
<listener>
<class>my.pack.CacheEventLogger</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>EXPIRED</events-to-fire-on>
</listener>
</listeners>
<resources>
<heap unit="entries">2</heap>
<offheap unit="MB">10</offheap>
<disk unit="MB">100</disk>
</resources>
</cache>
</config>
spring 配置:
@Configuration
@EnableCaching
public class EhcacheConfig {
@Bean
public CacheManager cacheManager() throws URISyntaxException {
JCacheCacheManager jCacheCacheManager = new JCacheCacheManager(Caching.getCachingProvider().getCacheManager(
getClass().getResource("/ehcache.xml").toURI(),
getClass().getClassLoader()
));
javax.cache.CacheManager cacheManager = jCacheCacheManager.getCacheManager();
Cache<Object, Object> powCache = cacheManager.getCache("pow_cache");
return jCacheCacheManager;
}
}
spring 引导版本为 2.1.6.RELEASE
ehcache 版本是 3.6.3
我做错了什么?如何纠正?
P.S.
我想我需要提及磁盘上缓存的文件位置,但我不知道在哪里。
我添加了
<persistence directory="spring-boot-ehcache/cache" />
在 <cache>
标记和堆栈跟踪消失之前