在class A上加@IocBean(create = "init“)后, 启动时类A有加载,但是init()方法没有被加载。
启动时日志:
14:17:50.145 DEBUG (AnnotationIocLoader.java:74) addClass - Found @IocBean : class com.×××××.common.×××.A
是因为ioc 懒加载导致的吗?
在class A上加@IocBean(create = "init“)后, 启动时类A有加载,但是init()方法没有被加载。
启动时日志:
14:17:50.145 DEBUG (AnnotationIocLoader.java:74) addClass - Found @IocBean : class com.×××××.common.×××.A
是因为ioc 懒加载导致的吗?
加了init 后,启动时报错Object 'com.cnaisin.common.cache.LocalCache' without define!:
配置如下:================================
@SetupBy(value=MainSetup.class)
@IocBy(type=ComboIocProvider.class,
init={"com.*****.common.***.A"},
args={"*js", "ioc/", "*anno", "com.cnaisin","*tx"
})
报错如下:
16:32:05.251 DEBUG (NutIoc.java:185) get - >> Load definition name=com.cnaisin.common.cache.LocalCache
16:32:05.251 ERROR (NutLoading.java:124) load - Error happend during start serivce!
org.nutz.ioc.IocException: [com.cnaisin.common.cache.LocalCache] # For object [com.cnaisin.common.cache.LocalCache] - type:[]
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:226) ~[nutz-1.r.57.jar:?]
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:265) ~[nutz-1.r.57.jar:?]
at org.nutz.mvc.impl.NutLoading.createIoc(NutLoading.java:391) ~[nutz-1.r.57.jar:?]
at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:102) ~[nutz-1.r.57.jar:?]
at org.nutz.mvc.ActionHandler.(ActionHandler.java:19) ~[nutz-1.r.57.jar:?]
at org.nutz.mvc.NutFilter._init(NutFilter.java:87) ~[nutz-1.r.57.jar:?]
at org.nutz.mvc.NutFilter.init(NutFilter.java:65) ~[nutz-1.r.57.jar:?]
at com.cnaisin.common.mvc.MvcNutzFilter.init(MvcNutzFilter.java:26) ~[classes/:?]
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279) ~[catalina.jar:8.5.4]
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260) ~[catalina.jar:8.5.4]
at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:105) ~[catalina.jar:8.5.4]
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4561) ~[catalina.jar:8.5.4]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5204) ~[catalina.jar:8.5.4]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152) ~[catalina.jar:8.5.4]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724) ~[catalina.jar:8.5.4]
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700) ~[catalina.jar:8.5.4]
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734) ~[catalina.jar:8.5.4]
at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1702) ~[catalina.jar:8.5.4]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_101]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_101]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_101]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_101]
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300) ~[tomcat-coyote.jar:8.5.4]
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) ~[?:1.8.0_101]
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) ~[?:1.8.0_101]
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:482) ~[catalina.jar:8.5.4]
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:431) ~[catalina.jar:8.5.4]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_101]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_101]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_101]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_101]
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300) ~[tomcat-coyote.jar:8.5.4]
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) ~[?:1.8.0_101]
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) ~[?:1.8.0_101]
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468) ~[?:1.8.0_101]
at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76) ~[?:1.8.0_101]
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309) ~[?:1.8.0_101]
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401) ~[?:1.8.0_101]
at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829) ~[?:1.8.0_101]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_101]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_101]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_101]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_101]
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:324) ~[?:1.8.0_101]
at sun.rmi.transport.Transport$1.run(Transport.java:200) ~[?:1.8.0_101]
at sun.rmi.transport.Transport$1.run(Transport.java:197) ~[?:1.8.0_101]
at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_101]
at sun.rmi.transport.Transport.serviceCall(Transport.java:196) ~[?:1.8.0_101]
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568) ~[?:1.8.0_101]
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826) ~[?:1.8.0_101]
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683) ~[?:1.8.0_101]
at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_101]
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682) [?:1.8.0_101]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_101]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_101]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_101]
Caused by: org.nutz.ioc.ObjectLoadException: Object 'com.cnaisin.common.cache.LocalCache' without define!
at org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:174) ~[nutz-1.r.57.jar:?]
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:188) ~[nutz-1.r.57.jar:?]
... 55 more
改为"localCache" 也报错了。
报错如下:=================
16:47:50.964 ERROR (NutLoading.java:124) load - Error happend during start serivce!
org.nutz.ioc.IocException: [localCache] # FAIL to create Ioc Bean name=[localCache]
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:149) ~[nutz-1.r.57.jar:?]
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:218) ~[nutz-1.r.57.jar:?]
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:265) ~[nutz-1.r.57.jar:?]
at org.nutz.mvc.impl.NutLoading.createIoc(NutLoading.java:391) ~[nutz-1.r.57.jar:?]
at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:102) ~[nutz-1.r.57.jar:?]
at org.nutz.mvc.ActionHandler.(ActionHandler.java:19) ~[nutz-1.r.57.jar:?]
at org.nutz.mvc.NutFilter._init(NutFilter.java:87) ~[nutz-1.r.57.jar:?]
at org.nutz.mvc.NutFilter.init(NutFilter.java:65) ~[nutz-1.r.57.jar:?]
at com.cnaisin.common.mvc.MvcNutzFilter.init(MvcNutzFilter.java:26) ~[classes/:?]
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279) ~[catalina.jar:8.5.4]
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260) ~[catalina.jar:8.5.4]
at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:105) ~[catalina.jar:8.5.4]
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4561) ~[catalina.jar:8.5.4]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5204) ~[catalina.jar:8.5.4]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152) ~[catalina.jar:8.5.4]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724) ~[catalina.jar:8.5.4]
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700) ~[catalina.jar:8.5.4]
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734) ~[catalina.jar:8.5.4]
at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1702) ~[catalina.jar:8.5.4]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_101]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_101]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_101]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_101]
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300) ~[tomcat-coyote.jar:8.5.4]
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) ~[?:1.8.0_101]
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) ~[?:1.8.0_101]
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:482) ~[catalina.jar:8.5.4]
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:431) ~[catalina.jar:8.5.4]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_101]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_101]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_101]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_101]
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300) ~[tomcat-coyote.jar:8.5.4]
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) ~[?:1.8.0_101]
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) ~[?:1.8.0_101]
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468) ~[?:1.8.0_101]
at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76) ~[?:1.8.0_101]
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309) ~[?:1.8.0_101]
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401) ~[?:1.8.0_101]
at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829) ~[?:1.8.0_101]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_101]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_101]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_101]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_101]
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:324) ~[?:1.8.0_101]
at sun.rmi.transport.Transport$1.run(Transport.java:200) ~[?:1.8.0_101]
at sun.rmi.transport.Transport$1.run(Transport.java:197) ~[?:1.8.0_101]
at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_101]
at sun.rmi.transport.Transport.serviceCall(Transport.java:196) ~[?:1.8.0_101]
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568) ~[?:1.8.0_101]
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826) ~[?:1.8.0_101]
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683) ~[?:1.8.0_101]
at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_101]
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682) [?:1.8.0_101]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_101]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_101]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_101]
Caused by: org.nutz.lang.born.BorningException: Fail to born 'com.cnaisin.common.cache.LocalCache'
by args: []
at org.nutz.lang.Mirror.getBorning(Mirror.java:954) ~[nutz-1.r.57.jar:?]
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:107) ~[nutz-1.r.57.jar:?]
... 56 more
按照这里的用法来看,无参数构造方法确认应该为public。
但是@IocBy中的init创建@IocBean对象时,对于private类型的无参构造参数要么给个提示,要么直接忽略public/private,直接构造对象。
错误提示不够明显,这个在1.r.58改好了. https://github.com/nutzam/nutz/commit/bc51782f42dcb6c1325f13028f596b7aef29b798
至于"直接忽略public/private,直接构造对象", 我不知道有什么API可以做到,请明示^_^