0

40 を超える Mbean を持つ Web アプリケーションがあります。Spring Framework を使用しました。

私はうまくやっており、うまく機能しています。しかし、私は 40 の Mbean を持っているので、一般化したいと思います。

@Component
@ManagedResource(objectName="ProjectCache:name=XMBean", log=true, logFile="jmx.log")
public class XMBean extends AbstractCacheMBean<String, XCO, XCache> { 

@ManagedOperation(description ="ProjectCache XCO key")
    @Override
    public List<String> showAllKeys(){  
        return super.getKey();      
    }

@ManagedOperation(description ="ProjectCache XCO")
public List<String> showAllElements(){  
    return super.findAll();     
}

@Override
public XCache getCache() {
    return getFacadeCache().getXCache();
}

@ManagedOperation(description ="ProjectCache XCO by key)
@Override
public String ShowbyKey(String key) {
    return super.findbyKey(key);
}

}

今、私は同じようにクラスYMbean、AMBeanなどを持っています。

アプリケーション mbean.xml で Spring を構成しました。

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/jee 
    http://www.springframework.org/schema/jee/spring-jee.xsd">

    <!-- this bean must not be lazily initialized if the exporting is to happen -->
    <bean id="exporter" class="org.springframework.jmx.export.MBeanExporter" lazy-init="false">
        <property name="server" ref="mbeanServer"/>
        <property name="assembler" ref="assembler" />
        <property name="namingStrategy" ref="namingStrategy" />         
    </bean>

    <bean id="jmxAttributeSource" class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource" />

    <!-- will create management interface using annotation metadata -->
    <bean id="assembler" class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler">
        <property name="attributeSource" ref="jmxAttributeSource" />
    </bean>

    <!-- will pick up the ObjectName from the annotation -->
    <bean id="namingStrategy" class="org.springframework.jmx.export.naming.MetadataNamingStrategy">
        <property name="attributeSource" ref="jmxAttributeSource" />
    </bean>

    <bean id="xMBean" 
        class="in.projet.business.mbean.XMBean"> 
        <property name="memoryCache" ref="repository" /> 
</bean>

同じように、YMbean クラスを準備し、xml で初期化します。

XMLの変更を必要としない、または作成するクラスの数を変更する必要がない場合、XMLを更新する必要はありません。

プロパティは、使用するすべての Mbean で同じです。すべてのアイデアや入力を歓迎します。

ありがとう

4

1 に答える 1

1

すべての構成を削除し、名前空間の使用に 1 回だけ置き換えます。また、MBean は@Components、簡単にスキャンできるようにするためのものです。次のxml行のみが残ります

<context:component-scan base-package="in.projet.business.mbean" />
<context:mbean-export/>

または、名前空間の代わりに現在の構成を保持したい場合は、少なくとも次のものに置き換えて、他のすべての Bean を削除します。これにより、アプリケーション コンテキストで MBean の自動検出が有効になります (これは基本的に と同じ<context:mbean-export />です。

詳細については、リファレンス ガイドのJMX の章を強くお勧めします。

于 2014-04-30T09:17:36.427 に答える