Main函数里面如何向Module中的@IocBean(fields={"dao"})传Dao对象
Main函数代码如下:
@IocBy(type=ComboIocProvider.class,args={"*org.nutz.ioc.loader.json.JsonLoader","ioc/",
"*org.nutz.ioc.loader.annotation.AnnotationIocLoader","tv.xingbo"})
@Encoding(input="utf8",output="utf8")
@Modules(scanPackage=true)
public class MainModule {
public static void main(String[] params){
Ioc ioc = new NutIoc(new JsonLoader("ioc.js"));
System.out.println(ioc);
UserModule userModule = new UserModule();
List<User> list = userModule.allLive();
for(int i = 0; i < list.size() ; i++){
User u = list.get(i);
System.out.println("User : id " + u.getId() + ", nick: " + u.getNick());
}
}
}
Module代码如下
@At("/User")
@IocBean(fields={"dao"})
public class UserModule extends EntityService<User>{
public List<User> allLive(){
List<User> list = dao().query(User.class,
Cnd.where("livestatus", "=", "1").and("liveforbid", "=", "0"));
return list;
}
}
Run的时候报空指针了,我觉得是Dao空指针了,报错内容如下:
2016-05-27 20:32:40,643 [main] DEBUG org.nutz.ioc.loader.json.JsonLoader - Loaded 2 bean define from path=[ioc/dao.js]
org.nutz.ioc.impl.NutIoc@5311a775
2016-05-27 20:32:40,669 [main] DEBUG org.nutz.service.EntityService - Get TypeParams for self : tv.xingbo.bean.User
Exception in thread "main" java.lang.NullPointerException
at tv.xingbo.module.UserModule.allLive(UserModule.java:28)
at tv.xingbo.MainModule.main(MainModule.java:38)
请问Main函数里面如何向Module中的@IocBean(fields={"dao"})传Dao对象?谢谢