Page 1 of 1

Issue with ehcache 2.5.1

Posted: Fri Apr 20, 2012 6:05 pm
by rgendler
Hi,

I 've noticed that Broadleaf libraries set a dependency for Ehcache 2.4.2 . In the environment that I am building and running Ehcache 2.5.1 is used. However I've noticed that switching to version 2.5.1 creates a strange duplicated cache exception.

Specifically I am seeing the following:

[artifact:mvn] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blCacheManager' defined in resource loaded from byte array: Invocation of init method failed; nested exception is net.sf.ehcache.ObjectExistsException: Cache hydrated-cache already exists
[artifact:mvn] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
[artifact:mvn] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
[artifact:mvn] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
[artifact:mvn] at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
[artifact:mvn] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
[artifact:mvn] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
[artifact:mvn] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
[artifact:mvn] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:281)
[artifact:mvn] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
[artifact:mvn] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563)
[artifact:mvn] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
[artifact:mvn] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
[artifact:mvn] at org.broadleafcommerce.profile.web.extensibility.MergeContextLoader.createWebApplicationContext(MergeContextLoader.java:104)
[artifact:mvn] at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
[artifact:mvn] at org.broadleafcommerce.profile.web.extensibility.MergeContextLoaderListener.contextInitialized(MergeContextLoaderListener.java:42)
.......

[artifact:mvn] Caused by: net.sf.ehcache.ObjectExistsException: Cache hydrated-cache already exists
[artifact:mvn] at net.sf.ehcache.C:197)
[artifact:mvn] at org.broadleafcommerce.profile.web.extensibility.MergeContextLoaderListener.contextInitialized(MergeContextLoaderListenacheManager.addCacheNoCheck(CacheManager.java:1150)
[artifact:mvn] at net.sf.ehcache.CacheManager.addConfiguredCaches(CacheManager.java:705)
[artifact:mvn] er.java:42)
[artifact:mvn] at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:548)
[artifact:mvn] at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)
[artifact:mvn] at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
[artifact:mvn] at org.morat net.sf.ehcache.CacheManager.doInit(CacheManager.java:423)
[artifact:mvn] at net.sf.ehcache.CacheManager.init(CacheManager.java:357)
[artifact:mvn] at net.sf.ehcache.CacheManager.<init>(CacheManager.java:242)
[artifact:mvn] at net.sf.ehcache.CacheManager.create(CacheManager.java:853)
[artifact:mvn] at net.sf.tbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
[artifact:mvn] at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContehcache.CacheManager.create(CacheManager.java:817)
[artifact:mvn] at org.springframework.cache.ehcache.EhCacheManagerFactoryBean.afterPropertiext.java:467)
[artifact:mvn] at org.mortbay.jetty.plugin.Jetty6PluginWebAppContext.doStart(Jetty6PluginWebAppContext.java:115)
[artifact:mvn] at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
[artifact:mvn] at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerColesSet(EhCacheManagerFactoryBean.java:103)
[artifact:mvn] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invoklection.java:152)
[artifact:mvn] at org.mortbay.jetty.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:156)
[artifact:mvn] at org.morteInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
[artifact:mvn] at org.springframework.beans.factory.support.AbstractAutowireCapablebay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
[artifact:mvn] at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
[artifact:mvn] ... 56 more


"hydrated-cache" is created by EhcacheHydratedCacheManagerImpl class, which is invoked by HydratedCacheEventListenerFactory

This listener factory is attached to "blStandardElements" cache definition in bl-ehcache.xml descriptor. It's also included in "mycompany-override-ehcache.xml" archetype definition under quick-start/ecommerce-archetype and hence shows up in every generated project.

It seems that disabling cacheEventListenerFactory removes the problem. However, I am not quite sure what are the implications of that.

Can you please clarify, how is this suppose to function?

Re: Issue with ehcache 2.5.1

Posted: Thu May 24, 2012 12:25 am
by rgendler
Any updates on this ? It's a very strange problem that I see with Ehcache v 2.5.1 and 2.5.2

Re: Issue with ehcache 2.5.1

Posted: Fri Jun 22, 2012 10:11 pm
by dchalloner
+1, I'm hitting the same issue when upgrading ehcache.

Re: Issue with ehcache 2.5.1

Posted: Thu Jun 28, 2012 10:06 am
by aazzolini
I attempted to use ehcache 2.5.2 and ran into the same issues you are running into.

I've created an issue in JIRA which you can use to follow updates here: http://jira.broadleafcommerce.org/browse/BLC-599

Re: Issue with ehcache 2.5.1

Posted: Mon Nov 05, 2012 2:20 pm
by rgendler
Was this issue ever resolved ? I am still seeing this as of BLC 2.0.1 with Ehcache 2.5.0 and beyond . I am also noticing BLC 2.0.1 references Ehcache 2.4.2


The suggested solution at http://jira.broadleafcommerce.org/browse/BLC-599 does not seem to work for me:
<bean id="blCacheManager"
class="org.broadleafcommerce.common.extensibility.cache.ehcache.MergeEhCacheManagerFactoryBean">
<property name="shared" value="true"/>
</bean>

in main applicationContext.xml still produces the same container init error I reported earlier.

Re: Issue with ehcache 2.5.1

Posted: Mon Nov 05, 2012 2:33 pm
by rgendler
As a temporary solution for now, I implemented my own version of HydaratedCacheManager extending from BLC AbstractHydratedCacheManager and using BLC EhcacheHydratedCacheManagerImpl as an example:

Something like

public class MyHydratedCacheManagerImpl extends AbstractHydratedCacheManager {
private static final Log LOG = LogFactory.getLog(MyHydratedCacheManagerImpl.class);
private static final MyHydratedCacheManagerImpl MANAGER = new MyHydratedCacheManagerImpl();

private Map<String, List<String>> cacheMembersByEntity =
Collections.synchronizedMap(new HashMap<String, List<String>>(100));
private Cache heap;

/**
* Private constructor
*/
private MyHydratedCacheManagerImpl() {
if (CacheManager.getInstance().cacheExists("mystore-cache")) {
heap = CacheManager.getInstance().getCache("mystore-cache");
} else {
CacheConfiguration config = new CacheConfiguration("mystore-cache", 0).eternal(true).overflowToDisk(false).maxEntriesLocalHeap(100000);
Cache cache = new Cache(config);
CacheManager.create().addCache(cache);
heap = cache;
LOG.info("Initialized mystore-cache");
}
}
..................
}

I than overwrite the existing HydratedCacheManager in override-ehcache descriptor

At this point it's not clear if I am just masking the existing problem or providing a true solution to this problem.

Re: Issue with ehcache 2.5.1

Posted: Mon Nov 05, 2012 6:03 pm
by aazzolini
Can you take a look at this pull request?

https://github.com/BroadleafCommerce/Br ... ce/pull/15

I think this is the same issue you're having, but I'm not 100% sure. Would you mind testing it?

You should get the fix by simply changing your Broadleaf version to "2.0.2-SNAPSHOT" in your pom.xml

Re: Issue with ehcache 2.5.1

Posted: Wed Nov 07, 2012 3:30 pm
by rgendler
Thank you for your reply,

I'll definitely try this ASAP.