Results 1 to 3 of 3

Thread: Managing ehcache via JMX

  1. #1

    Default Managing ehcache via JMX

    I have JMX working with Spring but I do not see ehcache in the list of MBeans. Is there something I must put in my application context to expose the ehcache mbean? Or do I have to write some code?

  2. #2

    Default

    I have tried pasting this code into my class which uses the cache:

    Code:
    		try {
    			CacheManager manager = new CacheManager();
    			MBeanServer mBeanServer = ManagementFactory
    					.getPlatformMBeanServer();
    			ManagementService.registerMBeans(manager, mBeanServer, false,
    					false, false, true);
    		} catch (RuntimeException e) {
    			e.printStackTrace();
    		}
    but I still don't see it..

  3. #3

    Default

    Found on
    http://wiki.burnayev.com/thread/1455...uration?t=anon

    and just copied here for further reference. It helped me a lot.

    Code:
    <bean id="hibernateStatisticsMBean"   class="org.hibernate.jmx.StatisticsService">
      <property name="statisticsEnabled" value="true"/>
      <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
    
    <bean id="ehCacheMBeanRegistration" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
      <property name="staticMethod"  value="net.sf.ehcache.management.ManagementService.registerMBeans"/>
      <property name="arguments">
        <list>
          <ref bean="cacheManager"/>
          <ref bean="mbeanServer"/>
          <value>true</value>
          <value>true</value>
          <value>true</value>
          <value>true</value>
        </list>
      </property>
    </bean>
    
    <bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
      <property name="locateExistingServerIfPossible" value="true"/>
    </bean>
    
    <bean id="mbeanExporter" class="org.springframework.jmx.export.MBeanExporter">
      <property name="beans">
        <map>
          <entry key="category=statistics,name=hibernate" value-ref="hibernateStatisticsMBean"/>
        </map>
      </property>
      <property name="server" ref="mbeanServer"/>
    </bean>
    
    <bean id="sessionFactory" class="..." >
      <property name="hibernateProperties">
      <props>
        ...
      <prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.SingletonEhCacheProvider</prop>
    <prop key="hibernate.generate_statistics">true</prop>
        ...
    </props>
    </property>
    </bean>
    
    <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
      <property name="configLocation" value="classpath:ehcache-hibernate.xml"/>
      <property name="shared" value="true"/>
    </bean>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •