在DemoConfig extends JFinalConfig 中
使用 @Inject 注入自己的 Service类 然后在 onStart 中使用会报 空指针错误。
使用 Aop.get(Service类) 启动的时候会报一系列错误。
2019-09-28 11:57:06 [ERROR]-[Thread: main]-[com.jfinal.proxy.ProxyCompiler.lambda$outputCompileError$0()]: /ScheduleService$$EnhancerByJFinal.java:3: 错误: 程序包com.jfinal.aop不存在 import com.jfinal.aop.Invocation; ^ 2019-09-28 11:57:06 [ERROR]-[Thread: main]-[com.jfinal.proxy.ProxyCompiler.lambda$outputCompileError$0()]: /ScheduleService$$EnhancerByJFinal.java:6: 错误: 程序包com.jfinal.kit不存在 public com.jfinal.kit.Ret saveAll(java.lang.String p0, java.lang.String p1, java.util.Map<java.lang.String, java.lang.Object> p2) { ^ 2019-09-28 11:57:06 [ERROR]-[Thread: main]-[com.jfinal.proxy.ProxyCompiler.lambda$outputCompileError$0()]: /ScheduleService$$EnhancerByJFinal.java:7: 错误: 找不到符号 Invocation inv = new Invocation(this, 1L, ^ 符号: 类 Invocation 位置: 类 com.liyesoft.jadmin.system.module.schedule.ScheduleService$$EnhancerByJFinal 2019-09-28 11:57:06 [ERROR]-[Thread: main]-[com.jfinal.proxy.ProxyCompiler.lambda$outputCompileError$0()]: /ScheduleService$$EnhancerByJFinal.java:7: 错误: 找不到符号 Invocation inv = new Invocation(this, 1L, ^ 符号: 类 Invocation 位置: 类 com.liyesoft.jadmin.system.module.schedule.ScheduleService$$EnhancerByJFinal java.lang.RuntimeException: java.lang.ClassNotFoundException: com.liyesoft.jadmin.system.module.schedule.ScheduleService$$EnhancerByJFinal at com.jfinal.proxy.ProxyClassLoader.loadProxyClass(ProxyClassLoader.java:51) at com.jfinal.proxy.ProxyFactory.getProxyClass(ProxyFactory.java:70) at com.jfinal.proxy.ProxyFactory.get(ProxyFactory.java:41) at com.jfinal.proxy.Proxy.get(Proxy.java:32) at com.jfinal.aop.AopFactory.createObject(AopFactory.java:173) at com.jfinal.aop.AopFactory.doGetSingleton(AopFactory.java:87) at com.jfinal.aop.AopFactory.doGet(AopFactory.java:65) at com.jfinal.aop.AopFactory.get(AopFactory.java:48) at com.jfinal.aop.Aop.get(Aop.java:101) at com.liyesoft.jadmin.system.JAdminConfig.<init>(JAdminConfig.java:32) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at java.lang.Class.newInstance(Class.java:442) at com.jfinal.core.JFinalFilter.createJFinalConfig(JFinalFilter.java:124) at com.jfinal.core.JFinalFilter.init(JFinalFilter.java:60) at io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:111) at io.undertow.servlet.core.ManagedFilter.createFilter(ManagedFilter.java:80) at io.undertow.servlet.core.DeploymentManagerImpl$2.call(DeploymentManagerImpl.java:591) at io.undertow.servlet.core.DeploymentManagerImpl$2.call(DeploymentManagerImpl.java:556) at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:42) at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43) at io.undertow.servlet.core.DeploymentManagerImpl.start(DeploymentManagerImpl.java:598) at com.jfinal.server.undertow.UndertowServer.configHttp(UndertowServer.java:284) at com.jfinal.server.undertow.UndertowServer.doStart(UndertowServer.java:262) at com.jfinal.server.undertow.UndertowServer.start(UndertowServer.java:159) at com.jfinal.server.undertow.UndertowServer.start(UndertowServer.java:92) at Run.main(Run.java:33) Caused by: java.lang.ClassNotFoundException: com.liyesoft.jadmin.system.module.schedule.ScheduleService$$EnhancerByJFinal at java.lang.ClassLoader.findClass(ClassLoader.java:530) at com.jfinal.proxy.ProxyClassLoader.findClass(ProxyClassLoader.java:64) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at com.jfinal.proxy.ProxyClassLoader.loadProxyClass(ProxyClassLoader.java:49) ... 28 more
项目:JFinal
1:新建一个启动类,例如:
public class App {
public void main(String[] args) {
UndertowServer.start(DemoConfig.class);
}
}
2: DemoConfig 中声明的属性不能直接支持注入(注入参考后面第三条),Aop.get(...) 只有有限的支持,因为创建 DemoConfig 的时候各种初始化还没进行,可以在 onStart() 方法中使用 Aop.get(...) 进行注入
3:可以在 DemoConfig 中的 onStart() 方法中通过 Aop.inject(this) 对 DemoConfig 中的 @Inject 属性进行注入