运行我的"编译时织女"时遇到错误来自Maven的类在我的Spring Boot 1.2.2 WAR中包含的JAR文件中。
所以,我有一个jar,ctms-components.jar,我使用MAVEN运行我的方面(例如,方法时间分析器)。然后,Spring Boot将它全部置于嵌入式WAR中(我使用Tomcat)。我看到了两个aspectj编织类,比如AJC Closures()等,我看到Maven的日志按照我的切入点编织我的类。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.7</version>
<configuration>
<showWeaveInfo>true</showWeaveInfo>
<source>${compiler.version}</source>
<target>${compiler.version}</target>
<Xlint>ignore</Xlint>
<complianceLevel>${compiler.version}</complianceLevel>
<encoding>UTF-8</encoding>
<verbose>false</verbose>
<aspectLibraries>
<aspectLibrary>
<groupId>cdot.ctms</groupId>
<artifactId>ctms-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
<weaveDependencies>
<weaveDependency>
<groupId>cdot.ctms</groupId>
<artifactId>ctms-components</artifactId>
</weaveDependency>
</weaveDependencies>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
以下是我的maven日志的摘录。
[INFO] Join point 'method-execution(cdot.base.DataAccessObject cdot.ctms.layer.services.comm.device.doppler.facade.DopplerFacade.getDopplerExchange())' in Type 'cdot.ctms.layer.services.comm.device.doppler.facade.DopplerFacade' (DopplerFacade.java:78) advised by around advice from 'cdot.aop.profiler.MethodTimerAspect' (ctms-aspects-2.0.0-SNAPSHOT.jar!MethodTimerAspect.class(from MethodTimerAspect.java))
[INFO] Join point 'method-execution(cdot.base.DataAccessObject cdot.ctms.layer.services.comm.device.doppler.facade.DopplerFacade.getDopplerRawDataExchange())' in Type 'cdot.ctms.layer.services.comm.device.doppler.facade.DopplerFacade' (DopplerFacade.java:84) advised by around advice from 'cdot.aop.profiler.MethodTimerAspect' (ctms-aspects-2.0.0-SNAPSHOT.jar!MethodTimerAspect.class(from MethodTimerAspect.java))
我的Spring Boot WAR显示AJC Closures捆绑在WAR中:
运行应用程序时得到的错误是:
java.lang.NoSuchMethodError:cdot.aop.profiler.MethodTimerAspect.aspectOf()Lcdot / aop / profiler / MethodTimerAspect
nested exception is java.lang.NoSuchMethodError: cdot.aop.profiler.MethodTimerAspect.aspectOf()Lcdot/aop/profiler/MethodTimerAspect;
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:121)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1502)
... 87 more
我不明白它为什么编译时编织,把它添加到我的Spring Boot WAR就好了,还包括ctms-aspects.jar,但在我的Aspect上找不到方法?
答案 0 :(得分:1)
AspectJ运行时库 aspectjrt.jar 必须位于类路径中,因此它应该是Maven <dependency>
,不仅适用于AspectJ Maven插件,还适用于Maven模块。