将 spring 引导从 1.5.12 迁移到 1.5.13 后,ehcache 出错
ehcache giving error after migrating spring boot from 1.5.12 to 1.5.13
我已经配置了 spring boot 1.5.12 + ehcache,一切正常,直到我将 spring boot 升级到 1.5.13
application.yml
有以下条目
spring:
cache:
jcache:
provider: org.ehcache.jsr107.EhcacheCachingProvider
config: ehcache.xml
我的 ehcache.xml
位于 resources
目录下
我收到的错误是:
Caused by: java.lang.IllegalArgumentException: Cache configuration does not exist 'ServletContext resource [/ehcache.xml]'
at org.springframework.util.Assert.isTrue(Assert.java:92)
at org.springframework.boot.autoconfigure.cache.CacheProperties.resolveConfigLocation(CacheProperties.java:117)
at org.springframework.boot.autoconfigure.cache.JCacheCacheConfiguration.createCacheManager(JCacheCacheConfiguration.java:113)
at org.springframework.boot.autoconfigure.cache.JCacheCacheConfiguration.jCacheCacheManager(JCacheCacheConfiguration.java:97)
at org.springframework.boot.autoconfigure.cache.JCacheCacheConfiguration$$EnhancerBySpringCGLIB$$e5c3a047.CGLIB$jCacheCacheManager(<generated>)
at org.springframework.boot.autoconfigure.cache.JCacheCacheConfiguration$$EnhancerBySpringCGLIB$$e5c3a047$$FastClassBySpringCGLIB$$a6ae7187.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358)
at org.springframework.boot.autoconfigure.cache.JCacheCacheConfiguration$$EnhancerBySpringCGLIB$$e5c3a047.jCacheCacheManager(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
... 47 common frames omitted
看起来 spring 启动已开始使用 servletContext 解析器搜索 ehcache.xml
。
p.s。除了 spring 引导升级到 1.5.13
之外,我没有对任何源代码进行任何更改
我是否遗漏了一些必需的配置?
我已经找到解决这个问题的方法。我们需要用文件名指定前缀 classpath:
以使其工作。
我的 application.yml
现在看起来像这样
spring:
cache:
jcache:
provider: org.ehcache.jsr107.EhcacheCachingProvider
config: classpath:ehcache.xml
希望对您有所帮助。
我已经配置了 spring boot 1.5.12 + ehcache,一切正常,直到我将 spring boot 升级到 1.5.13
application.yml
有以下条目
spring:
cache:
jcache:
provider: org.ehcache.jsr107.EhcacheCachingProvider
config: ehcache.xml
我的 ehcache.xml
位于 resources
目录下
我收到的错误是:
Caused by: java.lang.IllegalArgumentException: Cache configuration does not exist 'ServletContext resource [/ehcache.xml]'
at org.springframework.util.Assert.isTrue(Assert.java:92)
at org.springframework.boot.autoconfigure.cache.CacheProperties.resolveConfigLocation(CacheProperties.java:117)
at org.springframework.boot.autoconfigure.cache.JCacheCacheConfiguration.createCacheManager(JCacheCacheConfiguration.java:113)
at org.springframework.boot.autoconfigure.cache.JCacheCacheConfiguration.jCacheCacheManager(JCacheCacheConfiguration.java:97)
at org.springframework.boot.autoconfigure.cache.JCacheCacheConfiguration$$EnhancerBySpringCGLIB$$e5c3a047.CGLIB$jCacheCacheManager(<generated>)
at org.springframework.boot.autoconfigure.cache.JCacheCacheConfiguration$$EnhancerBySpringCGLIB$$e5c3a047$$FastClassBySpringCGLIB$$a6ae7187.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358)
at org.springframework.boot.autoconfigure.cache.JCacheCacheConfiguration$$EnhancerBySpringCGLIB$$e5c3a047.jCacheCacheManager(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
... 47 common frames omitted
看起来 spring 启动已开始使用 servletContext 解析器搜索 ehcache.xml
。
p.s。除了 spring 引导升级到 1.5.13
之外,我没有对任何源代码进行任何更改我是否遗漏了一些必需的配置?
我已经找到解决这个问题的方法。我们需要用文件名指定前缀 classpath:
以使其工作。
我的 application.yml
现在看起来像这样
spring:
cache:
jcache:
provider: org.ehcache.jsr107.EhcacheCachingProvider
config: classpath:ehcache.xml
希望对您有所帮助。