我有一个使用Java 8运行的Spring Boot应用程序。它运行良好,但有时会开始引发以下错误。

java.lang.NoClassDefFoundError: net/sf/ehcache/concurrent/ReadWriteLockSync
at net.sf.ehcache.store.MemoryStore$LockProvider.getSyncForKey(MemoryStore.java:1038)
at net.sf.ehcache.Cache.tryRemoveImmediately(Cache.java:2170)
at net.sf.ehcache.Cache.get(Cache.java:1756)
at org.springframework.cache.ehcache.EhCacheCache.lookup(EhCacheCache.java:142)
at org.springframework.cache.ehcache.EhCacheCache.get(EhCacheCache.java:67)
at org.springframework.cache.interceptor.AbstractCacheInvoker.doGet(AbstractCacheInvoker.java:73)
at org.springframework.cache.interceptor.CacheAspectSupport.findInCaches(CacheAspectSupport.java:527)
at org.springframework.cache.interceptor.CacheAspectSupport.findCachedItem(CacheAspectSupport.java:492)
at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:374)
at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:316)
at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:61)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689)

任何帮助,将不胜感激。

最佳答案

EhCache在版本2和版本3之间更改了软件包名称。

net.sf.ehcache引用EhCache2中的软件包(您的应用程序正在尝试查找此版本)

org.ehcache指的是新的EhCache3

可能是您有使用EhCache2的代码,现在失去了依赖性。例如,如果您尝试将Spring Boot 1.5更新为Spring Boot 2,则会发生这种情况

为了进行进一步的测试,请尝试在您的pom.xml中使用以下依赖项强制EhCache2:

    <dependency>
        <groupId>net.sf.ehcache</groupId>
        <artifactId>ehcache</artifactId>
        <version>2.10.5</version>
    </dependency>

10-04 23:14