学习ioc,根据文档demo,没看出来哪里错写错了啊。
js:
var ioc = {
xiaobai : {
name : 'XiaoBai',
birthday : '2009-10-25 15:23:40'
},
xiaohei : {
type : 'org.nutz.demo.Pet', // 类型
singleton : false, // 是否为单件
args : [ 'XiaoHei' ], // 构造函数参数
fields : {
birthday : '2009-11-3 08:02:14',
friend : {refer : 'xiaobai'} // 指向容器里另外一个对象
}
}
}
@Test
public void test_get_xiaohei() {
Ioc ioc = new NutIoc(new JsonLoader("pet.js"));
Pet pet = ioc.get(null, "xiaohei");
System.out.println(pet.getBirthday().getTimeZone().getID());
System.out.println(pet.getName());
ioc.depose();
}
ioc.get()方法指定类型或者null都报错。nutz使用1.r.65-SNAPSHOT版本
日志如下:
java.lang.RuntimeException: IocBean[xiaohei] fail at field=[friend]
at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:40)
at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:67)
at org.nutz.ioc.ObjectProxy.get(ObjectProxy.java:69)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:260)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:270)
at org.nutz.demo.PetTest.test_get_xiaohei(PetTest.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.nutz.ioc.IocException: IocBean[xiaobai] NULL TYPE object 'xiaobai'
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:213)
at org.nutz.ioc.val.ReferValue.get(ReferValue.java:24)
at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
... 27 more