首先看错误日志:
17-3-14 16:41:9.979 INFO [main] Fail to set value by field
org.nutz.castor.FailToCastObjectException: Fail to cast from <com.xx.xxservice.voucher.impl.ApplyInfoServiceImpl> to <com.xx.xx.service.assets.ApplyInfoService> for {com.xx.xx.service.voucher.impl.ApplyInfoServiceImpl@8acfc3} because:
BorningException:Fail to born 'com.xx.xx.service.assets.ApplyInfoService'
by args: [
@(com.yuro.dm.service.voucher.impl.ApplyInfoServiceImpl@8acfc3)] because: No suitable Constructor or Factory Method!!
at org.nutz.castor.Castors.cast(Castors.java:258)
at org.nutz.castor.Castors.castTo(Castors.java:318)
at org.nutz.lang.inject.InjectByField.inject(InjectByField.java:24)
at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:56)
at org.nutz.ioc.ObjectProxy.get(ObjectProxy.java:69)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:229)
at org.nutz.ioc.val.ReferValue.get(ReferValue.java:24)
at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:31)
at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:56)
at org.nutz.ioc.ObjectProxy.get(ObjectProxy.java:69)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:229)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
at com.yuro.dm.handler.AssetsHandlerlTest.setUp(AssetsHandlerlTest.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.nutz.lang.born.BorningException: Fail to born 'com.yuro.dm.service.assets.ApplyInfoService'
by args: [
@(com.yuro.dm.service.voucher.impl.ApplyInfoServiceImpl@8acfc3)] because: No suitable Constructor or Factory Method!!
at org.nutz.lang.Mirror.born(Mirror.java:988)
at org.nutz.castor.castor.Object2Object.cast(Object2Object.java:12)
at org.nutz.castor.Castors.cast(Castors.java:252)
... 35 more
这明明是说:
Fail to born 'com.yuro.dm.service.assets.ApplyInfoService'
因为我刚刚在一类(AssetHandler)里边引用了这个对象,
assetsHandler : {
type : 'com.xx.xx.handler.impl.AssetsHandlerImpl',
singleton : false,
fields : {
applyInfoService : {
refer : 'applyInfoService.assets'
}
}
}
所以就一直在检查这个引用和被引用的对象的ioc配置:
applyInfoService.assets : {
type : "com.xx.xx.service.assets.impl.ApplyInfoServiceImpl",
singleton : false,
fields : {
dao : {
refer : "dao"
}
}
}
但实际问题是出在另外一处引用到 applyInfoService.assets 的ioc配置中:
applyTaskService.assets : {
type : "com.xx.xx.service.assets.impl.ApplyTaskServiceImpl",
singleton : false,
fields : {
applyInfoService : {
refer : 'applyInfoService'
}
}
},
这里的refer应该指向 applyInfoService.assets , 但是日志里边没有体现,花了好些时间在检查正确的配置上边,也可能是我自己对日志的理解有问题?这里记录一下。