2016-08-21 6 views
1

Ich bekomme Caused by: java.lang.NullPointerException manchmal. Sieht aus wie Frühling ist nicht in der Lage, org.springframework.jmx.export.notification.NotificationPublisher richtig zu injizieren. Ich verwende Spring 2.5.6 und bin in WebSphere 7 implementiert. Wie können wir dieses NPE-Problem beheben?Feder 2.5.6 JMX NotificationPublisher-Aufruf, der NPE wirft

import javax.management.Notification; 

import org.springframework.jmx.export.notification.NotificationPublisher; 
import org.springframework.jmx.export.notification.NotificationPublisherAware; 

import com.xyz.SpringUtil; 
import com.xyz.notification.INotificationMBean; 
import com.xyz.security.impl.SpringSecurityHelper; 

/** 
* provides a central class for the publishing of Notifications. This allows us to centralize all notification 
* Listeners configuration in a central location, for this one MBean. 
*/ 
public class NotificationMBean implements INotificationMBean, NotificationPublisherAware { 

    /** used to publish notifications. This will be set automatically by Spring */ 
    private NotificationPublisher notificationPublisher; 
    private String proxyUser; // set by Spring - used for RMI-direct calls 
    private SpringSecurityHelper securityHelper; 

    protected SpringSecurityHelper getSecurityHelper() { 
     if (securityHelper == null) { 
      securityHelper = (SpringSecurityHelper) SpringUtil.getApplicationContext().getBean(
        SpringSecurityHelper.SPRING_SECURITY_HELPER); 
     } 

     return securityHelper; 
    } 

    protected void setSecurityHelper(SpringSecurityHelper securityHelper) { 
     this.securityHelper = securityHelper; 
    } 

    /** 
    * {@inheritDoc} 
    */ 
    public void publishNotification(Notification notif) { 
     getSecurityHelper().switchUserIfUnauthenticated(getProxyUser()); 
     getNotificationPublisher().sendNotification(notif); 
    } 

    /** 
    * Setter for notificationPublisher. 
    * @param notificationPublisher NotificationPublisher 
    */ 
    public void setNotificationPublisher(NotificationPublisher notificationPublisher) { 
     this.notificationPublisher = notificationPublisher; 
    } 

    /** 
    * Getter for the notificationPublisher. 
    * @return NotificationPublisher Returns the notificationPublisher. 
    */ 
    private NotificationPublisher getNotificationPublisher() { 
     return notificationPublisher; 
    } 

    /** 
    * {@inheritDoc} 
    */ 
    public String getProxyUser() { 
     return proxyUser; 
    } 

    /** 
    * {@inheritDoc} 
    */ 
    public void setProxyUser(String username) { 
     this.proxyUser = username; 
    } 
} 

Antwort

0

Der Fehler wird nach dem Hinzufügen der folgenden Erklärung zu meiner Feder Kontextdatei

<property name="notificationListeners"> 
      <list> 
       <bean class="com.xyz.mbean.impl.XYZNotificationListenerBean"> 
        <constructor-arg> 
         <ref bean="notificationListenerToDatabase" /> 
        </constructor-arg> 
        <property name="namingStrategy" ref="mbeanNamingStrategy" /> 
        <property name="mappedObjectNameTypePairs"> 
         <map> 
          <entry> 
           <key> 
            <value>sequenceGeneratorEarNotificationMBean</value> 
           </key> 
           <ref bean="NotificationMBean" /> 
          </entry> 
         </map> 
        </property> 
       </bean> 
       <bean class="com.xyz.mbean.impl.XYZNotificationListenerBean"> 
        <constructor-arg> 
         <ref bean="notificationListenerToTopic" /> 
        </constructor-arg> 
        <property name="namingStrategy" ref="mbeanNamingStrategy" /> 
        <property name="mappedObjectNameTypePairs"> 
         <map> 
          <entry> 
           <key> 
            <value>sequenceGeneratorEarNotificationMBean</value> 
           </key> 
           <ref bean="NotificationMBean" /> 
          </entry> 
         </map> 
        </property> 
       </bean> 
       <bean class="com.xyz.mbean.impl.XYZNotificationListenerBean"> 
        <constructor-arg ref="notificationListenerToExternal" /> 
        <property name="namingStrategy" ref="mbeanNamingStrategy" /> 
        <property name="mappedObjectNameTypePairs"> 
         <map> 
          <entry key="sequenceGeneratorEarNotificationMBean" value-ref="NotificationMBean" /> 
         </map> 
        </property> 
       </bean> 
      </list> 
     </property> 
    </bean> 
gegangen
Verwandte Themen