Spring Monitoring Ehcache MBean

I am using Spring 4.0.3.RELEASE and EHcache 2.8.1. on JBoss 7.1.1

With the following configuration in applicationContext.xml my caching works well.

 <cache:annotation-driven/> <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager"> <property name="cacheManager" ref="ehcache"/> </bean> <bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"> <property name="configLocation" value="/WEB-INF/ehcache.xml"/> </bean> 

Now I want to add monitoring capabilities using MBean. I changed the configuration in applicationContext.xml as follows: 2 new beans "managementService" and "mbeanServer" were added, no other changes. This is the current configuration.

 <cache:annotation-driven/> <bean id="managementService" class="net.sf.ehcache.management.ManagementService" init-method="init" destroy-method="dispose"> <constructor-arg ref="cacheManager"/> <constructor-arg ref="mbeanServer"/> <constructor-arg index="2" value="true"/> <constructor-arg index="3" value="true"/> <constructor-arg index="4" value="true"/> <constructor-arg index="5" value="true"/> </bean> <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager"> <property name="cacheManager" ref="ehcache"/> </bean> <bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"> <property name="configLocation" value="/WEB-INF/ehcache.xml"/> </bean> <bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"> <property name="locateExistingServerIfPossible" value="true"/> </bean> 

With this configuration, I get the following error when starting the application server.

 14:05:32,208 ERROR [org.springframework.web.context.ContextLoader] (MSC service thread 1-1) Context initialization failed: org.springframework.beans.factory.UnsatisfiedDependencyException: **Error creating bean with name 'managementService'** defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [net.sf.ehcache.CacheManager]: Could not convert constructor argument value of type [org.springframework.cache.ehcache.EhCacheCacheManager] to required type [net.sf.ehcache.CacheManager]: Failed to convert value of type 'org.springframework.cache.ehcache.EhCacheCacheManager' to required type 'net.sf.ehcache.CacheManager'; nested exception is java.lang.IllegalStateException: **Cannot convert value of type [org.springframework.cache.ehcache.EhCacheCacheManager] to required type [net.sf.ehcache.CacheManager]**: no matching editors or conversion strategy found Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'managementService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [net.sf.ehcache.CacheManager]: Could not convert constructor argument value of type [org.springframework.cache.ehcache.EhCacheCacheManager] to required type [net.sf.ehcache.CacheManager]: Failed to convert value of type 'org.springframework.cache.ehcache.EhCacheCacheManager' to required type 'net.sf.ehcache.CacheManager'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.springframework.cache.ehcache.EhCacheCacheManager] to required type [net.sf.ehcache.CacheManager]: no matching editors or conversion strategy found 
+6
source share
1 answer

You must pass the ehcache bean to the managementService bean not cacheManager . If you look at the definition of cacheManager , then the ehcache bean is passed as cacheManager . factory bean will provide an instance of net.sf.ehcache.CacheManager .

+6
source

All Articles