Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Ehcache MBean Monitoring

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 is working good.

<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 the monitoring capabilities with MBean. I changed the configuration in applicationContext.xml as follows – added 2 new beans “managementService” and “mbeanServer”, no other change. 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 on application server start up.

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
like image 350
Sam Avatar asked Apr 25 '14 08:04

Sam


People also ask

How do you monitor Ehcache?

Turn the statistics flag to true in the cache in the Ehcache. xml file per the following example. Copy the monitor package to a monitoring server. To start the monitor, run the startup script that is provided in the bin directory: startup.sh in Unix and startup.

How do I know if my Ehcache is empty?

ehcache. hibernate under Mbeans tab. Click on the CacheRegionStats Clicking on it will open bring up the screen on the right. Double click on top section and it brings up the tabular navigation as shown below.

How does Ehcache work?

Ehcache can assist you with reducing the likelihood that stale data is used by your application by expiring cache entries after some amount of configured time. Once expired, the entry is automatically removed from the cache.

Where is Ehcache stored?

All the data is kept in the authority tier, which is slower but more abundant. Data stores supported by Ehcache include: On-Heap Store - Utilizes Java's on-heap RAM memory to store cache entries. This tier utilizes the same heap memory as your Java application, all of which must be scanned by the JVM garbage collector.


1 Answers

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

like image 102
Priyesh Avatar answered Sep 18 '22 10:09

Priyesh