我是在一个定时器的线程中去取ioc中已有的dao,如下:
NutMvcContext ctx;
try {
ctx = Mvcs.ctx();
if (ctx == null) {
System.out.println("无法获取nutz运行环境!");
return;
}
Ioc ioc = ctx.getDefaultIoc();
dao = ioc.get(DaoImpl.class, "dao");
} catch (Exception e) {
e.printStackTrace();
}
失败:
java.lang.NullPointerException
at org.nutz.mvc.Mvcs.getServletContext(Mvcs.java:379)
at org.nutz.mvc.Mvcs.ctx(Mvcs.java:293)
at com.jinyatu.module.MessageAndTaskTimerTask.run(MessageAndTaskTimerTask.java:37)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
Exception in thread "Timer-4" java.lang.NullPointerException
at com.jinyatu.module.MessageAndTaskTimerTask.reloadTaskList(MessageAndTaskTimerTask.java:90)
at com.jinyatu.module.MessageAndTaskTimerTask.run(MessageAndTaskTimerTask.java:48)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
nutz版本:nutz-1.r.54.r2