我有时候会import java.util.Scanner;
public class clock
{
public static void main(String[] args)
throws InterruptedException
{
Scanner Input = new Scanner(System.in);
System.out.print("HOUR: ");
int hrs = Input.nextInt();
System.out.print("MIN: ");
int min = Input.nextInt();
System.out.print("SEC: ");
int sec = Input.nextInt();
while (true)
{
System.out.println(hrs + ":" + min + ":" + sec);
sec = sec + 1;
if (sec > 59)
{
sec = 0;
min = min + 1;
}
if (min > 59)
{
min = 0;
hrs = hrs + 1;
}
if (hrs > 12)
{
hrs = 1;
}
Thread.sleep (1000);
}
}
}
。
看起来spring无法正确注入Caused by: java.lang.NullPointerException
。我使用的是Spring 2.5.6并在WebSphere 7中部署。
我们如何解决这个NPE问题?
org.springframework.jmx.export.notification.NotificationPublisher
答案 0 :(得分:0)
将以下声明添加到我的spring上下文文件
后,错误消失了<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>