2013-01-18 4 views
0

mon XML de configuration: appconfig.xmlSpring Framework 3.0 Avis JMX pas reçu

<beans xmlns="..."> 

    <context:mbean-server/> 
    <bean id="exporter" class="org.springframework.jmx.export.MBeanExporter" lazy-init="false"> 
     <property name="beans"> 
      <map> 
       <entry key="bean:name=notificationSender" value-ref="notificationSenderImpl"></entry> 
       <entry key="bean:name=notificationListener" value-ref="notificationListenerImpl"></entry> 
      </map> 
     </property> 
    <property name="notificationListenerMappings"> 
        <map> 
       <entry key="notificationListenerImpl" value-ref="notificationListenerImpl"></entry> 
      </map>    
     </property> 

     <property name="server" ref="mbeanServer"/>  
    </bean> 
    <bean id="notificationSender" class="com....NotificationSenderImpl"/> 
    <bean id="notificationListener" class="com....NotificationListenerImpl"/> 

mon code: Test.java

@RunWith(SpringJUnit4ClassRunner.class) 
@ContextConfiguration("classpath:appconfig.xml") 
public class Test { 
    @Autowired 
    private ConfigurableApplicationContext context; 

    @Test 
    public void testFlow() { 
     NotificationSender sender = (NotificationSender) context.getBean("notificationSender");  
       sender.send(); 
    } 

    @After 
    public void tearDown(){ 
     context.close(); 
    } 

} 

classe NotificationSenderImpl.java

public class NotificationSenderImpl implements NotificationPublisherAware{ 

     private NotificationPublisher notificationPublisher; 

    public void setNotificationPublisher(NotificationPublisher notificationPublisher) { 
     // TODO Auto-generated method stub 
     this.notificationPublisher = notificationPublisher;  
    } 

    public void send(){ 
     notificationPublisher.sendNotification(new Notification("simple", this, 0L)); 
    } 
} 

et l'écouteur ... class NotificationListenerImpl

public class NotificationListenerImpl implements NotificationListener{ 

    public void handleNotification(Notification notification, Object handback) { 

     // TODO Auto-generated method stub 
     System.out.println("Notification received"); 
    } 

} 

Les notifications sont envoyées mais pas reçues. Des pointeurs?

Répondre

1

Vous ne savez pas si vous avez déjà résolu ce problème, mais je verrai si je peux vous aider. J'ai récemment joué avec Spring/JMX et je suis encore nouveau, mais j'espère pouvoir partager quelques idées.

Je ne pense pas que vous ayez besoin de déclarer l'écouteur comme un MBean à exporter, seulement les beans qui vont publier des notifications. Deuxièmement, je crois que la clé dans la notificationListenerMappings est destinée à être le ObjectName du MBean, pas une référence au bean de l'auditeur lui-même. En d'autres termes ..

<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter" lazy-init="false"> 
    <property name="beans"> 
     <map> 
      <entry key="bean:name=notificationSender" value-ref="notificationSenderImpl"></entry> 
     </map> 
    </property> 
    <property name="notificationListenerMappings"> 
     <map> 
      <entry key="bean:name=notificationSender" value-ref="notificationListenerImpl"></entry> 
     </map>    
    </property> 
    <property name="server" ref="mbeanServer"/>  
</bean> 

Vous pouvez également utiliser des jokers pour les clés de mappage auditeur. Voici un exemple de mon propre MBeanExporter, qui reprend les notifications de toutes mes déclarées annotation-MBeans:

<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter"> 
    . 
    . 
    . 
    <property name="notificationListenerMappings"> 
     <map> 
      <entry key="*"> 
       <bean class="com.poc.jmx.domain.NotificationBroadcastListener" /> 
      </entry> 
     </map> 
    </property> 
</bean> 

espoir qui aide.