Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何为JMX监控设置net.sf.ehcache.CacheManager的名称?_Java_Spring_Jmx_Ehcache_Mbeans - Fatal编程技术网

Java 如何为JMX监控设置net.sf.ehcache.CacheManager的名称?

Java 如何为JMX监控设置net.sf.ehcache.CacheManager的名称?,java,spring,jmx,ehcache,mbeans,Java,Spring,Jmx,Ehcache,Mbeans,我正在使用JRE 1.6在Tomcat6上部署的web应用程序中使用Ehcache1.4.0和Spring3.0.5。我通过JMX公开二级缓存管理,如下所示: <bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"> <property name="locateExistingServerIfPossible" value="true" /> <

我正在使用JRE 1.6在Tomcat6上部署的web应用程序中使用Ehcache1.4.0和Spring3.0.5。我通过JMX公开二级缓存管理,如下所示:

<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
    <property name="locateExistingServerIfPossible" value="true" />
</bean>

<util:property-path id="hibernateCacheProvider" path="sessionFactory.settings.cacheProvider" />

<bean id="hibernateEhCacheManager" class="com.mycompany.spring.beans.factory.config.UnaccessibleFieldRetrievingFactoryBean">
    <property name="targetObject" ref="hibernateCacheProvider" />
    <property name="targetField" value="manager" />
    <property name="makeInstanceFieldVisible" value="true" />
</bean>

<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <description>The cacheManager configuration.</description>
    <property name="targetClass" value="net.sf.ehcache.management.ManagementService" />
    <property name="staticMethod" value="net.sf.ehcache.management.ManagementService.registerMBeans" />
    <property name="arguments">
        <list>
            <ref bean="hibernateEhCacheManager" />
            <ref bean="mbeanServer" />
            <value type="boolean">true</value>
            <value type="boolean">true</value>
            <value type="boolean">true</value>
            <value type="boolean">true</value>
        </list>
    </property>
</bean>

<bean class="org.springframework.jmx.export.annotation.AnnotationMBeanExporter">
    <property name="server" ref="mbeanServer" />
    <property name="beans">
        <map>
            <entry key="Hibernate:type=statistics,application=applicationOne">
                <bean class="org.hibernate.jmx.StatisticsService">
                    <property name="statisticsEnabled" value="true" />
                    <property name="sessionFactory" ref="sessionFactory" />
                </bean>
            </entry>
        </map>
    </property>
</bean>

<bean id="hbm.properties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    <property name="properties">
        <props>
            <prop key="hibernate.show_sql">false</prop>
            <prop key="hibernate.generate_statistics">false</prop>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop>
            <prop key="hibernate.cache.use_query_cache">true</prop>
            <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
            <prop key="hibernate.cache.provider_configuration_file_resource_path">applicationOne-web/ehcache.xml</prop>
            <prop key="hibernate.cache.query_cache_factory">org.hibernate.cache.StandardQueryCacheFactory</prop>
        </props>
    </property>
</bean>
run --bean net.sf.ehcache:type=CacheManager,name=net.sf.ehcache.CacheManager@605df3c5 clearAll
我知道如何从上下文中确定确切的
CacheManager
,但由于某些原因,我可能不会使用它

到目前为止还不错,但假设我的JVM(Tomcat服务器)部署了2个应用程序,这两个应用程序都允许JMX监视EhCache。这两个MBean的名称为:

net.sf.ehcache:type=CacheManager,name=net.sf.ehcache.CacheManager@605df3c5
net.sf.ehcache:type=CacheManager,name=net.sf.ehcache.CacheManager@49ff3459
正如您所看到的,在尝试确定要清除哪个缓存时,它们不是很有用

所以我的问题是:是否有可能设置每个CacheManager的名称,以便准确地确定使用哪一个来清除二级缓存中的所有条目


谢谢。

一旦hibernateEhCacheManager可用,就可以使用以下bean定义调用其方法(设置include)。通常,这应该可以完成重命名CacheManager的任务

 <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
        <property name="targetObject">
            <ref local="hibernateEhCacheManager"/>
        </property>
        <property name="targetMethod">
            <value>setName</value>
        </property>
        <property name="arguments" value="<the_desired_name>"/>
</bean>

集合名

我知道这个问题很久以前就得到了回答,但我认为在您的ehcache配置文件(applicationOne web/ehcache.xml)中设置它更容易


...