我的maven项目使用spring aop,一切正常。现在因为 blablabla ,我需要使用aspectj,我在config中添加了aspectj依赖项和aspectj maven插件
<aspectj.version>1.8.2</aspectj.version>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.7</version>
<configuration>
<showWeaveInfo>true</showWeaveInfo>
<source>${java-version}</source>
<target>${java-version}</target>
<Xlint>ignore</Xlint>
<complianceLevel>${java-version}</complianceLevel>
<encoding>UTF-8</encoding>
<verbose>true</verbose>
<sources><source><basedir>src/main/java</basedir></source></sources>
</configuration>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>compile</goal><!-- use this goal to weave all your main classes -->
</goals>
</execution>
</executions>
</plugin>
当maven构建项目时,输出如下:
[INFO]
[INFO] --- aspectj-maven-plugin:1.7:compile (default) @ wolverine-ris ---
[INFO] Showing AJC message detail for messages of types: [error, warning, fail]
[WARNING] Missing message: configure.invalidClasspathSection in: org.aspectj.ajdt.ajc.messages
<unknown source file>:<no line information>
[INFO] Join point 'method-execution(org.springframework.web.context.request.async.DeferredResult
我认为目标类应该在编译后输出多个类 像这样: expected generated classes
但在我的情况下,只编织了一个班级。
当我调用控制器时,有一个空指针执行。
java.lang.NullPointerException: null
at com.*.*.*.hotel.controller.HotelController.getHotelFLag_aroundBody1$advice(HotelController.java:79) ~[HotelController.class:na]
at com.*.*.*.hotel.controller.HotelController.getHotelFLag(HotelController.java:1) ~[HotelController.class:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_30]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ~[na:1.6.0_30]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_30]
at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_30]
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219) ~[spring-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) ~[spring-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) ~[spring-webmvc-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745) ~[spring-webmvc-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686) ~[spring-webmvc-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) ~[spring-webmvc-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925) [spring-webmvc-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) [spring-webmvc-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936) [spring-webmvc-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827) [spring-webmvc-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621) [servlet-api.jar:na]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812) [spring-webmvc-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) [servlet-api.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) [catalina.jar:7.0.40]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) [catalina.jar:7.0.40]
at com.**.web.filter.AccessOriginFilter.doFilterInternal(AccessOriginFilter.java:34) [nfbird-spring-mvc-1.3.0-SNAPSHOT.jar:na]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) [catalina.jar:7.0.40]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) [catalina.jar:7.0.40]
at com.**.web.filter.DecodingFilter.doFilterInternal(DecodingFilter.java:47) [nfbird-spring-mvc-1.3.0-SNAPSHOT.jar:na]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) [catalina.jar:7.0.40]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) [catalina.jar:7.0.40]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) [spring-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) [catalina.jar:7.0.40]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) [catalina.jar:7.0.40]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) [catalina.jar:7.0.40]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) [catalina.jar:7.0.40]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) [catalina.jar:7.0.40]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) [catalina.jar:7.0.40]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) [catalina.jar:7.0.40]
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) [catalina.jar:7.0.40]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) [catalina.jar:7.0.40]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) [catalina.jar:7.0.40]
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1008) [tomcat-coyote.jar:7.0.40]
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) [tomcat-coyote.jar:7.0.40]
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) [tomcat-coyote.jar:7.0.40]
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [na:1.6.0_30]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [na:1.6.0_30]
at java.lang.Thread.run(Thread.java:662) [na:1.6.0_30]
任何帮助将不胜感激。
==========================更新1 =================== =======
我将aspectj maven插件版本更改为1.6,将$ {aspectj.version}更改为1.7.4,警告消息未显示
[INFO] --- aspectj-maven-plugin:1.6:compile (default) @ wolverine-ris ---
Downloading: http://nexus.**.org/nexus/content/groups/public/org/aspectj/aspectjtools/1.7.4/aspectjtools-1.7.4.pom
Downloaded: http://nexus.**.org/nexus/content/groups/public/org/aspectj/aspectjtools/1.7.4/aspectjtools-1.7.4.pom (1021 B at 26.9 KB/sec)
Downloading: http://nexus.**.org/nexus/content/groups/public/org/aspectj/aspectjtools/1.7.4/aspectjtools-1.7.4.jar
Downloaded: http://nexus.**.org/nexus/content/groups/public/org/aspectj/aspectjtools/1.7.4/aspectjtools-1.7.4.jar (9784 KB at 38518.7 KB/sec)
[INFO] Join point 'method-execution(org.springframework.web.context.request.async.DeferredResult com.**.train.controller.TrainTicketController.queryTrainTickets(com.**.train.actor.message.QueryTrainTicketVo))' in Type 'com.**.train.controller.TrainTicketController' (TrainTicketController.java:47) advised by around advice from 'com.**.kafka.aspect.RequestAspect' (RequestAspect.java:41)
[INFO] Join point 'method-execution(org.springframework.web.context.request.async.DeferredResult com.**.train.controller.TrainTicketController.queryTrainTicketsByTrainId(com.**.train.actor.message.QueryTrainTicketVo))' in Type 'com.**.train.controller.TrainTicketController' (TrainTicketController.java:72) advised by around advice from 'com.**.kafka.aspect.RequestAspect' (RequestAspect.java:41)
[INFO] Join point 'method-execution(org.springframework.web.context.request.async.DeferredResult com.**.hotelflow.controller.StreamHotelController.queryHotelsForPlayPrd(com.**.hotel.actor.message.QueryHotelVo))' in Type 'com.**.hotelflow.controller.StreamHotelController' (StreamHotelController.java:33) advised by around advice from 'com.**.kafka.aspect.RequestAspect' (RequestAspect.java:41)
....
但是当我调用控制器时,仍然有一个空指针execption(上面发布)。
答案 0 :(得分:0)
我已经解决了问题,npe异常是由于注释不正确造成的。 当我使用spring aop时,我就这样写了,最近我没有改变它
@Aspect
public class RequestAspect extends AbstractAspect {
@Injected
private KafkaLog kafkaLog;
....
}
我用另一种方式来获取kafkaLog bean而不是注释,一切正常,所以我现在不关心 $ AjcClosure .class的东西。^ _ ^