public static <T> T instance(Class<T> c, String iocPath) throws Exception {
Ioc ioc = new NutIoc(new JsonLoader(iocPath));
Mirror<?> mirror = Mirror.me(c);
T obj = c.newInstance();
for (Field field : mirror.getFields()) {
Inject inject = field.getAnnotation(Inject.class);
if (inject != null) {
if (field.getType().equals(org.apache.log4j.Logger.class)) {
LOG.warn("org.apache.log4j.Logger Deprecated please use org.slf4j.Logger by LoggerFactory");
mirror.setValue(obj, field, org.apache.log4j.Logger.getLogger(c));
} else if (field.getType().equals(org.slf4j.Logger.class)) {
mirror.setValue(obj, field, LoggerFactory.getLogger(c));
} else {
mirror.setValue(obj, field, ioc.get(field.getType(), StringUtil.isBlank(inject.value()) ? field.getName() : inject.value()));
}
}
}
return obj;
}
想通过ioc文件实例化一个对象.然后调用这个对象的方法..之前都好好的升级后报如下错误
13:03:33,220 ERROR org.nutz.ioc.impl.NutIoc - Ioc depose tigger by GC!!!
Common Reason for that is YOUR code call 'new NutIoc(...)', and then get some beans(most is Dao) from it and abandon it!!!
If using nutz.mvc, call Mvcs.ctx().getDefaultIoc() to get ioc container.
org.nutz.ioc.IocException: [tokenizerService] # For object [tokenizerService] - type:[class cn.com.infcn.mss.TokenizerService]
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:218)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
at cn.com.infcn.mss.query.parse.MethodExe.method(MethodExe.java:66)
at cn.com.infcn.mss.query.parse.Parse.invoke(Parse.java:73)
at cn.com.infcn.mss.query.parse.Parse.format(Parse.java:85)
at cn.com.infcn.msp.MssSearchApi._queryParse(MssSearchApi.java:299)
at cn.com.infcn.msp.MssSearchApi.queryParse(MssSearchApi.java:211)
at cn.com.infcn.mss.MssSearchApiTest.queryParseTest(MssSearchApiTest.java:69)
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.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
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.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: org.nutz.ioc.ObjectLoadException: Object 'tokenizerService' without define!
at org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:174)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:180)
... 31 more