2010-11-25 7 views
9

Springを使用して@ManagedResourceアノテーションを使用してManagedBeanをコンフィグレーションしました。また、これにJMX NotificationListenerをマッピングしました。 しかし、リスナーがキックオフ/実行されないことがわかった。ここでSpring JMX NotificationListenerを作成できません

は、関連する設定ファイルです:

@ManagedResource(description = "My Mbean", objectName = "com.sample:bean=myMBean") 
public class MyMBean { 

    private boolean isAvailable = true; 

    @ManagedAttribute(description = "isAvailable", defaultValue = "true") 
    public void setAvailable(boolean flag) { 
     this.isAvailable = flag; 
    } 
} 

そして最後に、ここでNotificationListenerのように見える方法は次のとおりです:

public class MyMBeanNotificationListener implements 
     NotificationListener { 

    @Override 
    public void handleNotification(Notification notification, Object handback) { 
     System.out.println("In Notification Listener" + notification); 
    } 

} 
ここ

<beans xmlns="http://www.springframework.org/schema/beans" 
    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-2.5.xsd"> 

    <bean id="myMBeanServer" 
     class="org.springframework.jmx.support.MBeanServerFactoryBean"> 
     <!-- indicate to first look for a server --> 
     <property name="locateExistingServerIfPossible" value="true" /> 
    </bean> 

    <!-- MBean auto exporter --> 
    <bean id="exporter" class="org.springframework.jmx.export.MBeanExporter" 
     lazy-init="false"> 
     <property name="server" ref="myMBeanServer" /> 
     <property name="assembler" ref="assembler" /> 
     <property name="namingStrategy" ref="namingStrategy" /> 
     <property name="notificationListenerMappings"> 
      <map> 
       <entry key="myMBean" 
        value-ref="myMBeanNotificationListener" /> 
      </map> 
     </property> 
    </bean> 

    <!-- The assembler --> 
    <bean id="assembler" 
     class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler"> 
     <property name="attributeSource" ref="attributeSourceStrategy" /> 
    </bean> 

    <!-- The naming strategy --> 
    <bean id="namingStrategy" 
     class="org.springframework.jmx.export.naming.MetadataNamingStrategy"> 
     <property name="attributeSource" ref="attributeSourceStrategy" /> 
    </bean> 

    <!-- The attributeSource strategy --> 
    <bean id="attributeSourceStrategy" 
     class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource" /> 

    <!-- MyMBean --> 
    <bean id="myMBean" 
     class="com.sample.MyMBean" /> 

    <!-- MBean Notification Listener --> 
    <bean id="myMBeanNotificationListener" 
     class="com.sample.MyMBeanNotificationListener" /> 
</beans> 

MyMBeanクラスがどのように見えるかです

NotificationListenerがいいえの理由がわからない実行されていますか?コードによってスローされた例外はありません。

誰もJMX NotificationListenerさんとSpringを使用していますか?

+1

'MyMBean'が通知を公表していない場合、あなたは何を期待していますか? – axtavt

+0

axtavt、私の以前の質問を確認してくださいhttp://stackoverflow.com/questions/4260398/jmx-spring-when-is-a-jmxnotification-bcastcasted誰かが属性の変更がJMX通知をブロードキャストすることを確認しました。上記のリスナーと一緒に、私はそれを捉えることを望んでいました。パブリッシャーを持つ必要があり、属性の変更が自動的に通知を送信しないことは確かですか?ありがとう! – peakit

+0

あなたの前の質問に対する答えにリンクされた記事は、あなたが手動で 'AttributeChangeNotification'を放送する必要があることを明らかにしています。 – axtavt

答えて

0

jConsoleまたはjVisualVMに通知が表示されていますか?

変更してみてください:

<entry key="myMBean" value-ref="myMBeanNotificationListener" /> 

へ:

<entry key="com.sample:bean=myMBean" value-ref="myMBeanNotificationListener" /> 

ないの通知のために、あなたが上記のXMLをsimpify可能性がある場合:

<context:mbean-export default-domain="myDomain"/> 
関連する問題