ehcache 2.9的这篇文档说它将支持RMI,JGroups和JMS。但是,很明显,ehcache-2.9 JAR中的API已经更改,文档也不是最新的。在我得到下面的错误后,仔细看看它的EhCache ClassLoaderUtils确认这个方法(getStandardClassLoader())确实不存在。
我正在寻找有关如何解决此问题的明智之举,因此我可以在ehcache 2.9中使用JGroups复制。
我正在使用最新的ehcache-jgroupsreplication maven依赖:
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-jgroupsreplication</artifactId>
<version>1.7</version>
</dependency>
Caused by: net.sf.ehcache.CacheException: java.lang.NoSuchMethodError: net.sf.ehcache.util.ClassLoaderUtil.getStandardClassLoader()Ljava/lang/ClassLoader;
at net.sf.ehcache.CacheManager.init(CacheManager.java:426)
at net.sf.ehcache.CacheManager.<init>(CacheManager.java:270)
at org.springframework.cache.ehcache.EhCacheManagerFactoryBean.afterPropertiesSet(EhCacheManagerFactoryBean.java:157)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1625)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1562)
... 39 more
Caused by: java.lang.NoSuchMethodError: net.sf.ehcache.util.ClassLoaderUtil.getStandardClassLoader()Ljava/lang/ClassLoader;
at net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory.createCachePeerProvider(JGroupsCacheManagerPeerProviderFactory.java:61)
at net.sf.ehcache.config.ConfigurationHelper.createCachePeerProviders(ConfigurationHelper.java:136)
at net.sf.ehcache.CacheManager.configure(CacheManager.java:795)
at net.sf.ehcache.CacheManager.doInit(CacheManager.java:471)
at net.sf.ehcache.CacheManager.init(CacheManager.java:395)
... 43 more
答案 0 :(得分:5)
我想出来并为其他人发布答案以获益。
我必须创建自己的自定义“JGroupsCacheManagerPeerProviderFactory”,而不是使用ehcache-jgroupsreplication 1.7 maven依赖项中的那个。
真的,唯一的改变是使用不同的类加载而不是调用ehcache-2.9.jar中不再存在的API:
//final ClassLoader contextClassLoader = ClassLoaderUtil.getStandardClassLoader();
// CHANGE: Use Thread's contextClassLoader instead of invalid API
final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
然后,在ehcache.xml中,我注册了这样的自定义,而不是在ehcache-jgroupsreplication JAR中注册工厂:
<cacheManagerPeerProviderFactory
class="my.custom.JGroupsCacheManagerPeerProviderFactory"
properties="file=jgroups/jgroups-unified-udp.xml"/>