我新建了一个service类:
public class DemoService { public void show () { System.out.print("hi jfinal") } }
控制器代码:
@RequestMapping("/demo") public class DemoController extends Controller { // 方式一 失败 // @Inject // DemoService demoService; // 方式二 正常,不过下面这个方法好像过时了 DemoService demoService = Enhancer.enhance(DemoService.class); public void index(){ demoService.show(); } }
使用 方式一 进行注入时,当在浏览器访问路径时,报错:
java.lang.NoSuchMethodError: com.jfinal.aop.Enhancer.enhance(Ljava/lang/Class;[Lcom/jfinal/aop/Interceptor;)Ljava/lang/Object; at com.qyvip.libra.aop.LibraAopFactory.createObject(LibraAopFactory.java:129) at com.jfinal.aop.AopFactory.doGetSingleton(AopFactory.java:87) at com.jfinal.aop.AopFactory.doGet(AopFactory.java:65) at com.qyvip.libra.aop.LibraAopFactory.doInjectJFinalOrginal(LibraAopFactory.java:199) at com.qyvip.libra.aop.LibraAopFactory.doInject(LibraAopFactory.java:156) at com.jfinal.aop.AopFactory.inject(AopFactory.java:125) at com.jfinal.aop.Aop.inject(Aop.java:105) at com.qyvip.libra.web.handler.LibraActionHandler.handle(LibraActionHandler.java:75) at com.qyvip.libra.web.handler.LibraHandler.doHandle(LibraHandler.java:31) at com.qyvip.libra.web.handler.LibraHandler.handle(LibraHandler.java:19) at com.qyvip.libra.web.handler.LibraFilterHandler.handle(LibraFilterHandler.java:30) at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:89) at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61) at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84) at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62) at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68) at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:132) at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46) at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64) at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60) at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77) at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at io.undertow.servlet.handlers.SessionRestoringHandler.handleRequest(SessionRestoringHandler.java:119) at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292) at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81) at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138) at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135) at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48) at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43) at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272) at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81) at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104) at io.undertow.server.Connectors.executeRootHandler(Connectors.java:364) at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)
为啥用@Inject注解会注入失败呢。。。
com.qyvip.libra这个是公司的jar包,我看和jfinal中的类是一样的