http://ehcache.org/generated/2.9.0/html/ehc-all/#page/Ehcache_Documentation_Set%2Fco-use_supported_types.html%23wwconnect_header
This documentation from ehcache 2.9 says it will support RMI, JGroups, and JMS. But, clearly, the APIs in ehcache-2.9 JAR have changed and the docs are not up-to-date. After I got the error below, a closer look at its EhCache ClassLoaderUtils confirms this method (getStandardClassLoader()) indeed, does not exist.
I'm looking for bright ideas on how to work around this issue, so I can use JGroups replication in ehcache 2.9.
I am using the latest ehcache-jgroupsreplication maven dependency:
<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
I figured it out and post answer for others to benefit.
I had to create my own custom "JGroupsCacheManagerPeerProviderFactory" instead of using the one in the ehcache-jgroupsreplication 1.7 maven dependency.
Really, the only change to it was to use a different classload and NOT call the API that no longer exists in ehcache-2.9.jar :
//final ClassLoader contextClassLoader = ClassLoaderUtil.getStandardClassLoader();
// CHANGE: Use Thread's contextClassLoader instead of invalid API
final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
Then, in ehcache.xml, I registered my custom one like this, instead of registering the factory in the ehcache-jgroupsreplication JAR:
<cacheManagerPeerProviderFactory
class="my.custom.JGroupsCacheManagerPeerProviderFactory"
properties="file=jgroups/jgroups-unified-udp.xml"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With