net.sf.ehcache.CacheException: Another CacheManager with same name 'fernowebapp' already exists in the same VM. Please provide unique names for each CacheManage
r in the config or do one of following:
1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary
2. Shutdown the earlier cacheManager before creating new one with same name.
This is the web.xml
<servlet>
<servlet-name>ferno</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<!-- <load-on-startup>1</load-on-startup> -->
</servlet>
<servlet-mapping>
<servlet-name>ferno</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/ferno-servlet.xml</param-value>
</context-param>
<context-param>
<param-name>contextInitializerClasses</param-name>
<param-value>com.vuelogix.collygo.context.FernoApplicationContextInitializer</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
When i inspected the log , i found the application context is initialized twice. I just verified it by disabling the load on start up for dispatcher servlet. When i disable the dispatcher servlet , i found the exception doesnt comes at the time of start up. But it occurs when i first try to hit any controller class.
i found few similar issues in Why does Spring MVC need at least two contexts? , Spring - application Initialized twice?
in the link below its mentioned that for Ehcache 2.5 and higher does not allow multiple CacheManagers with the same name to exist in the same JVM. CacheManager() constructors creating non-Singleton CacheManagers can violate this rule.
Another unnamed CacheManager already exists in the same VM (ehCache 2.5)
If the application context is to be loaded again for initializing dispatcher servlet, What is the best way to initialize classes like CacheManager ?
I believe it will work if i add init params for dispatcher servlet. mentioned in comment. In my case, I dont have a seperate application context for dispatcher servlet, So i believe it works fine in my application context. Update: So , when i really need a seperate application context for my dispatcher servlet, the best practice will be to remove the cache declaration(in this case) from the second context and make those configuration on root config? Correct me if i am wrong