gpt4 book ai didi

ehcache - 如何集成 EhCache 2.9 和 JGroups 复制?

转载 作者:行者123 更新时间:2023-12-02 11:05:42 28 4
gpt4 key购买 nike

http://ehcache.org/generated/2.9.0/html/ehc-all/#page/Ehcache_Documentation_Set%2Fco-use_supported_types.html%23wwconnect_header

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

最佳答案

我弄清楚了并发布答案以供其他人受益。

我必须创建自己的自定义“JGroupsCacheManagerPeerProviderFactory”,而不是使用 ehcache-jgroupsreplication 1.7 maven 依赖项中的“JGroupsCacheManagerPeerProviderFactory”。

实际上,唯一的改变是使用不同的类加载,并且不调用 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"/>

关于ehcache - 如何集成 EhCache 2.9 和 JGroups 复制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29298776/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com