Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java IllegalStateException:找不到可持久化资源磁盘[ehCache 3]的服务_Java_Ehcache_Spring Cache_Jcache - Fatal编程技术网

Java IllegalStateException:找不到可持久化资源磁盘[ehCache 3]的服务

Java IllegalStateException:找不到可持久化资源磁盘[ehCache 3]的服务,java,ehcache,spring-cache,jcache,Java,Ehcache,Spring Cache,Jcache,我想在应用程序重新启动后使缓存可用,并在配置中添加了以下行: <disk unit="MB">100</disk> 100 在启动应用程序后,我有以下stacktrace: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheManager' defined in class path resource [my/pack/Ehcache

我想在应用程序重新启动后使缓存可用,并在配置中添加了以下行:

<disk unit="MB">100</disk>
100
在启动应用程序后,我有以下stacktrace:

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$0(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$$1811178.CGLIB$cacheManager$0(<generated>) ~[main/:na]
    at my.pack.EhcacheConfig$$EnhancerBySpringCGLIB$$1811178$$FastClassBySpringCGLIB$$9c04d8c0.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$$1811178.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
org.springframework.beans.factory.BeanCreationException:创建名为“cacheManager”的bean时出错,该bean在类路径资源[my/pack/EhcacheConfig.class]中定义:通过工厂方法实例化bean失败;嵌套异常为org.springframework.beans.beanInstationException:未能实例化[org.springframework.cache.CacheManager]:工厂方法“CacheManager”引发异常;嵌套异常为org.ehcache.StateTransitionException:在EhcacheManager中创建缓存“pow_Cache”失败。
在org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627)~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
在org.springframework.beans.factory.support.ConstructorResolver.InstanceUsingFactoryMethod(ConstructorResolver.java:456)~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.InstanceUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321)~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160)~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
在org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
在org.springframework.beans.factory.support.DefaultListableBeanFactory.PreInstanceSingleton(DefaultListableBeanFactory.java:845)~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877)~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
在org.springframework.boot.SpringApplication.refresh(SpringApplication.java:742)~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
在org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:389)~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
在org.springframework.boot.SpringApplication.run(SpringApplication.java:311)~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
在org.springframework.boot.SpringApplication.run(SpringApplication.java:1213)~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
在org.springframework.boot.SpringApplication.run(SpringApplication.java:1202)~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
在my.pack.Main.Main(Main.java:12)~[Main/:na]
原因:org.springframework.beans.beans实例化异常:未能实例化[org.springframework.cache.CacheManager]:工厂方法“CacheManager”引发异常;嵌套异常为org.ehcache.StateTransitionException:在EhcacheManager中创建缓存“pow_Cache”失败。
在org.springframework.beans.factory.support.SimpleInstallationStrategy.instantiate(SimpleInstallationStrategy.java:185)~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
在org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622)~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
... 省略18个公共框架
原因:org.ehcache.StateTransitionException:在EhcacheManager中创建缓存“pow_Cache”失败。
在org.ehcache.core.StatusTransitioner$Transition.failed(StatusTransitioner.java:235)~[ehcache-3.6.3.jar:3.6.3 03c2e612075c4e06bc994817543ab7512486b689]
在org.ehcache.core.EhcacheManager.init(EhcacheManager.java:603)~[ehcache-3.6.3.jar:3.6.3 03c2e612075c4e06bc994817543ab7512486b689]
在org.ehcache.jsr107.EhcacheCachingProvider.createCacheManager(EhcacheCachingProvider.java:155)~[ehcache-3.6.3.jar:3.6.3 03c2e612075c4e06bc994817543ab7512486b689]
在org.ehcache.jsr107.EhcacheCachingProvider.getCacheManager(EhcacheCachingProvider.java:131)~[ehcache-3.6.3.jar:3.6.3 03c2e612075c4e06bc994817543ab7512486b689]
在org.ehcache.jsr107.EhcacheCachingProvider.getCacheManager(EhcacheCachingProvider.java:82)~[ehcache-3.6.3.jar:3.6.3 03c2e612075c4e06bc994817543ab7512486b689]
在org.ehcache.jsr107.EhcacheCachingProvider.getCacheManager(EhcacheCachingProvider.java:190)~[ehcache-3.6.3.jar:3.6.3 03c2e612075c4e06bc994817543ab7512486b689]
在my.pack.EhcacheConfig.cacheManager(EhcacheConfig.java:19)~[main/:na]
在my.pack.EhcacheConfig$$EnhancerBySpringCGLIB$$1811178.CGLIB$cacheManager$0()~[main/:na]
在my.pack.EhcacheConfig$$EnhancerBySpringCGLIB$$1811178$$FastClassBySpringCGLIB$$9c04d8c0.invoke()~[main/:na]
在org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)~[spring-core-5.1.8.RELEASE.jar:5.1.8.RELEASE]
位于org.springframework.context.annotation。
<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>
@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;
    }
}
<persistence directory="spring-boot-ehcache/cache" />