未收到Spring Framework 3.0 JMX通知
我的配置XML:appconfig.XML未收到Spring Framework 3.0 JMX通知,spring,spring-jmx,Spring,Spring Jmx,我的配置XML:appconfig.XML <beans xmlns="..."> <context:mbean-server/> <bean id="exporter" class="org.springframework.jmx.export.MBeanExporter" lazy-init="false"> <property name="beans"> <map>
<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"/>
类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));
}
}
还有监听器…类通知ListenerImpl
public class NotificationListenerImpl implements NotificationListener{
public void handleNotification(Notification notification, Object handback) {
// TODO Auto-generated method stub
System.out.println("Notification received");
}
}
正在发送通知,但未收到。有什么建议吗?不确定您是否已解决此问题,但我会看看是否能提供帮助。我最近一直在玩spring/JMX,我还是新手,但希望我能分享一些见解 我认为您不需要将侦听器声明为要导出的MBean,只需要将发布通知的bean。其次,我认为notificationListenerMappings中的键是MBean的ObjectName,而不是对侦听器bean本身的引用。换句话说
<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>
您还可以对侦听器映射键使用通配符。下面是我自己的MBeanExporter的一个示例,它从所有注释声明的MBean中拾取通知:
<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>
.
.
.
希望有帮助
<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>