Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/398.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 Springboot和Ehcache-多缓存异常_Java_Spring Boot_Ehcache_Jsr107 - Fatal编程技术网

Java Springboot和Ehcache-多缓存异常

Java Springboot和Ehcache-多缓存异常,java,spring-boot,ehcache,jsr107,Java,Spring Boot,Ehcache,Jsr107,我试图将缓存添加到springboot应用程序中,但遇到了一个问题,在启动过程中引发了org.ehcache.jsr107.MultiCacheException异常 我正在使用以下文件(全部通过Maven pom文件加载): Springboot 1.5.5、Ehcache 3.3.1、Javax cache 1.0.0 我的SpringBoot应用程序如下所示: @SpringBootApplication @EnableCaching public class DemoApplicatio

我试图将缓存添加到springboot应用程序中,但遇到了一个问题,在启动过程中引发了org.ehcache.jsr107.MultiCacheException异常

我正在使用以下文件(全部通过Maven pom文件加载): Springboot 1.5.5、Ehcache 3.3.1、Javax cache 1.0.0

我的SpringBoot应用程序如下所示:

@SpringBootApplication
@EnableCaching
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}
我有一个包含以下内容的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));
    }
}
最后,application.properties包含:

<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>
@Service
public class ItemService {

    @CacheResult(cacheName = "item")
    public String getItem(int itemNumber) {
        switch (itemNumber) {
            case 1:
                return "Item 1";
            case 2:
                return "Item 2";
            default:
                return "No Item";

        }
    }
}
spring.cache.jcache.config=classpath:ehcache.xml
当我运行应用程序时,会出现以下异常,以结束:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jCacheCacheManager' defined in class path resource [org/springframework/boot/autoconfigure/cache/JCacheCacheConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.cache.CacheManager]: Factory method 'jCacheCacheManager' threw exception; nested exception is org.ehcache.jsr107.MultiCacheException: [Exception 0] org.terracotta.ehcache.EventLogger
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    ... 70 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.cache.CacheManager]: Factory method 'jCacheCacheManager' threw exception; nested exception is org.ehcache.jsr107.MultiCacheException: [Exception 0] org.terracotta.ehcache.EventLogger
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    ... 83 common frames omitted
Caused by: org.ehcache.jsr107.MultiCacheException: [Exception 0] org.terracotta.ehcache.EventLogger
    at org.ehcache.jsr107.ConfigurationMerger.mergeConfigurations(ConfigurationMerger.java:138) ~[ehcache-3.3.1.jar:3.3.1 01f4b2121ef38b7e7d95c952c773881d5b1051d8]
    at org.ehcache.jsr107.Eh107CacheManager.createCache(Eh107CacheManager.java:190) ~[ehcache-3.3.1.jar:3.3.1 01f4b2121ef38b7e7d95c952c773881d5b1051d8]
    at com.example.cacheexample.CacheConfig.customize(CacheConfig.java:18) ~[classes/:na]
    at org.springframework.boot.autoconfigure.cache.JCacheCacheConfiguration.customize(JCacheCacheConfiguration.java:149) ~[spring-boot-autoconfigure-1.5.5.RELEASE.jar:1.5.5.RELEASE]
    at org.springframework.boot.autoconfigure.cache.JCacheCacheConfiguration.jCacheCacheManager(JCacheCacheConfiguration.java:104) ~[spring-boot-autoconfigure-1.5.5.RELEASE.jar:1.5.5.RELEASE]
    at org.springframework.boot.autoconfigure.cache.JCacheCacheConfiguration$$EnhancerBySpringCGLIB$$e218d7d3.CGLIB$jCacheCacheManager$1(<generated>) ~[spring-boot-autoconfigure-1.5.5.RELEASE.jar:1.5.5.RELEASE]
    at org.springframework.boot.autoconfigure.cache.JCacheCacheConfiguration$$EnhancerBySpringCGLIB$$e218d7d3$$FastClassBySpringCGLIB$$b2f1636b.invoke(<generated>) ~[spring-boot-autoconfigure-1.5.5.RELEASE.jar:1.5.5.RELEASE]
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.boot.autoconfigure.cache.JCacheCacheConfiguration$$EnhancerBySpringCGLIB$$e218d7d3.jCacheCacheManager(<generated>) ~[spring-boot-autoconfigure-1.5.5.RELEASE.jar:1.5.5.RELEASE]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    ... 84 common frames omitted
原因:org.springframework.beans.factory.BeanCreationException:创建名为“JCacheCacheCacheManager”的bean时出错,该名称在类路径资源[org/springframework/boot/autoconfigure/cache/JCacheCacheCacheCacheCacheCacheConfiguration.class]中定义:通过工厂方法实例化bean失败;嵌套异常为org.springframework.beans.BeanInstantiationException:未能实例化[javax.cache.CacheManager]:工厂方法“JCacheCacheCacheManager”引发异常;嵌套异常为org.ehcache.jsr107.multicacheeption:[异常0]org.terracotta.ehcache.EventLogger
在org.springframework.beans.factory.support.ConstructorResolver.InstanceUsingFactoryMethod(ConstructorResolver.java:599)~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.InstanceUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173)~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067)~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
在org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
在org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208)~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
在org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
在org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
在org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835)~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
在org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
... 省略70个公共框架
原因:org.springframework.beans.BeanInstantiationException:未能实例化[javax.cache.CacheManager]:工厂方法“JCacheCacheCacheManager”引发异常;嵌套异常为org.ehcache.jsr107.multicacheeption:[异常0]org.terracotta.ehcache.EventLogger
在org.springframework.beans.factory.support.SimpleInstallationStrategy.instantiate(SimpleInstallationStrategy.java:189)~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
在org.springframework.beans.factory.support.ConstructorResolver.InstanceUsingFactoryMethod(ConstructorResolver.java:588)~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
... 省略了83个公共框架
原因:org.ehcache.jsr107.MultiCacheException:[异常0]org.terracotta.ehcache.EventLogger
在org.ehcache.jsr107.configurationmerge.mergeConfigurations(configurationmerge.java:138)~[ehcache-3.3.1.jar:3.3.1 01f4b2121ef38b7e7d95c952c773881d5b1051d8]
在org.ehcache.jsr107.Eh107CacheManager.createCache(Eh107CacheManager.java:190)~[ehcache-3.3.1.jar:3.3.1 01f4b2121ef38b7e7d95c952c773881d5b1051d8]
在com.example.cacheexample.CacheConfig.customize(CacheConfig.java:18)~[classes/:na]
在org.springframework.boot.autoconfigure.cache.JCacheCacheConfiguration.customize(JCacheCacheConfiguration.java:149)~[spring-boot-autoconfigure-1.5.5.RELEASE.jar:1.5.5.RELEASE]
在org.springframework.boot.autoconfigure.cache.JCacheCacheConfiguration.jCacheCacheManager(JCacheCacheConfiguration.java:104)~[spring-boot-autoconfigure-1.5.5.RELEASE.jar:1.5.5.RELEASE]
在org.springframework.boot.autoconfigure.cache.JCacheCacheConfiguration$$EnhancerBySpringCGLIB$$e218d7d3.CGLIB$jCacheCacheManager$1()~[spring-boot-autoconfigure-1.5.5.RELEASE.jar:1.5.5.5.RELEASE]
在org.springframework.boot.autoconfigure.cache.JCacheCacheConfiguration$$EnhancerBySpringCGLIB$$e218d7d3$$FastClassBySpringCGLIB$$b2f1636b.invoke()~[spring-boot-autoconfigure-1.5.5.RELEASE.jar:1.5.5.5.RELEASE]
在org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)~[spring-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
在org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358)~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
在org.spring