22
22
import javax .management .Notification ;
23
23
import javax .management .ObjectName ;
24
24
25
+ import org .springframework .beans .factory .BeanFactory ;
25
26
import org .springframework .beans .factory .BeanFactoryAware ;
26
27
import org .springframework .beans .factory .BeanFactoryUtils ;
27
28
import org .springframework .beans .factory .InitializingBean ;
@@ -60,7 +61,6 @@ public class NotificationPublishingMessageHandler extends AbstractMessageHandler
60
61
61
62
private String defaultNotificationType ;
62
63
63
- @ Nullable
64
64
private OutboundMessageMapper <Notification > notificationMapper ;
65
65
66
66
@@ -109,11 +109,12 @@ public String getComponentType() {
109
109
110
110
@ Override
111
111
public final void onInit () {
112
- Assert .isTrue (this .getBeanFactory () instanceof ListableBeanFactory , "A ListableBeanFactory is required." );
112
+ BeanFactory beanFactory = getBeanFactory ();
113
+ Assert .isTrue (beanFactory instanceof ListableBeanFactory , "A ListableBeanFactory is required." );
113
114
Map <String , MBeanExporter > exporters =
114
- BeanFactoryUtils .beansOfTypeIncludingAncestors ((ListableBeanFactory ) getBeanFactory () ,
115
+ BeanFactoryUtils .beansOfTypeIncludingAncestors ((ListableBeanFactory ) beanFactory ,
115
116
MBeanExporter .class );
116
- Assert .isTrue (exporters .size () > 0 , "No MBeanExporter is available in the current context." );
117
+ Assert .state (exporters .size () > 0 , "No MBeanExporter is available in the current context." );
117
118
MBeanExporter exporter = null ;
118
119
for (MBeanExporter exp : exporters .values ()) {
119
120
exporter = exp ;
@@ -124,9 +125,11 @@ public final void onInit() {
124
125
if (this .notificationMapper == null ) {
125
126
this .notificationMapper = new DefaultNotificationMapper (this .objectName , this .defaultNotificationType );
126
127
}
127
- exporter .registerManagedResource (this .delegate , this .objectName );
128
- if (this .logger .isInfoEnabled ()) {
129
- this .logger .info ("Registered JMX notification publisher as MBean with ObjectName: " + this .objectName );
128
+ if (exporter != null ) {
129
+ exporter .registerManagedResource (this .delegate , this .objectName );
130
+ if (this .logger .isInfoEnabled ()) {
131
+ this .logger .info ("Registered JMX notification publisher as MBean with ObjectName: " + this .objectName );
132
+ }
130
133
}
131
134
}
132
135
0 commit comments