在mvcSetUp 启动加载 IOC bean,偶尔会出现创建bean失败的问题,但极大多数启动,都没问题的,不知道,这与加载的顺序有关吗??
以下是我使用的过程:
@IocBy(type = ComboIocProvider.class, args = {"*org.nutz.ioc.loader.json.JsonLoader", "ioc",
"*org.nutz.ioc.loader.annotation.AnnotationIocLoader", "x.x.x.x"})
@Encoding(input = "utf8", output = "utf8")
@Modules(scanPackage = true)
@SetupBy(MvcSetup.class)
@ChainBy(args = "ioc/chain.js")
@Chain("mainChain")
@Localization("msg")
@Views(BaseViewMaker.class)
@Ok("json")
@Fail("json")
public class MainModule {
}
public class MvcSetup implements Setup {
public void init(NutConfig config) {
....
CommonContext.ioc = config.getIoc();
X.register(CommonContext.ioc.get(Y.class));
X.register(CommonContext.ioc.get(Z.class));
.....
}
}
package x.x.x.x.x
@IocBean
public class Y {
private K k= CommonContext.ioc.get(K .class);
....
}
package x.x.x.x.x
@IocBean
public class Z {
private H h= CommonContext.ioc.get(H .class);
...
}
报错信息:
2017-09-14 23:02:28,728 [localhost-startStop-1] ERROR x.x.x.x.x.MvcSetup.init(MvcSetup.java:72) MvcSetup|init|fail|"errorMessage"="[Z] # FAIL to create Ioc Bean name=[Z]"
org.nutz.ioc.IocException: [Z] # FAIL to create Ioc Bean name=[Z]
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:149)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:218)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:265)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:150)
at x.x.x.x.x.MvcSetup.init(MvcSetup.java:64)
at org.nutz.mvc.impl.NutLoading.evalSetup(NutLoading.java:276)
at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:120)
......
Caused by: org.nutz.lang.born.BorningException: Fail to born 'x.x.x.x.x.Z' becasue: java.lang.NullPointerException
at org.nutz.lang.born.EmptyArgsConstructorBorning.born(EmptyArgsConstructorBorning.java:19)
at org.nutz.ioc.weaver.DefaultWeaver.born(DefaultWeaver.java:67)
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:114)
... 26 more
疑惑的问题一:Y 和 Z 类基本都差不多的加载,为啥Y加载没问题,而Z加载偶尔报错。