Fed*_*zza 17 java spring aspectj java-8 aspectj-maven-plugin
我正在将我的项目从java 7迁移到java 8,我遇到的问题与使用aspectj编织有关aspectj-maven-plugin
.
根据Haus文档,我可以使用在Java 6和7上运行的这个插件成功配置编织.但问题是我还没有找到任何方法来使用(并找到)支持java 8的插件版本7.我在这里看到插件7增加了java 8支持,但找不到使用它的方法.
这是我需要的配置插件:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.7</version> <!-- AspectJ weaver plugin 7 is for java 8 (version 1.6 is for java 7) -->
<configuration>
<complianceLevel>1.8</complianceLevel>
<source>1.8</source>
<target>1.8</target>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
我确认使用版本1.6的上述代码适用于Java 7,但没有运气试图使用1.7版.
你知道如何运行在Java 8上运行的spring + aspectj的weaver吗?
Fed*_*zza 33
经过许多头痛和许多小时的努力,幸运的是我可以解决这个问题.这是我做的:
要aspectj-maven-plugin
与Java 8一起使用,我可以配置版本aspectj-maven-plugin 1.7(注意,aspectj-maven-plugin 1.6适用于Java 7).
因此,maven插件配置需要:
<!-- AspectJ configuration -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.7-SNAPSHOT</version>
<configuration>
<complianceLevel>1.8</complianceLevel>
<source>1.8</source>
<target>1.8</target>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
顺便说一句,所需的aspectJ罐子是:
<!-- Spring AOP + AspectJ -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>4.0.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.1</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我一直在努力的最重要的事情是安装aspectj-maven-plugin 1.7 jar我必须手动完成它,因为这些jar/pom文件还没有在maven repo上.
更新:因此,jar文件可以从Haus Jira链接下载(查看附件部分).如果Haus不再可用,您可以从我的github下载它:
https://github.com/fedepia/aspectj-maven-plugin-1.7
下载后将其复制到我的本地仓库我需要在目录中创建自己的 aspectj-maven-plugin-1.7-SNAPSHOT.pom
文件:
.m2\repository\org\codehaus\mojo\aspectj-maven-plugin\1.7-SNAPSHOT\aspectj-maven-plugin-1.7-SNAPSHOT.pom
Run Code Online (Sandbox Code Playgroud)
我基于1.6版的副本,但必须修改以下内容:
<version>1.7-SNAPSHOT</version>
<properties>
<aspectjVersion>1.8.1</aspectjVersion>
<mavenVersion>2.2.1</mavenVersion>
<changesPluginVersion>2.9</changesPluginVersion>
</properties>
Run Code Online (Sandbox Code Playgroud)
这就是你去的地方,希望能有所帮助.
更新:(添加更多细节,如Xtreme Biker在评论中提到的)
在我的上下文配置中,我有:
<aop:aspectj-autoproxy />
<bean id="notificationAspect" class="com.integration.core.aspect.NotificationAspect" factory-method="aspectOf" scope="singleton"></bean>
Run Code Online (Sandbox Code Playgroud)
对于我的java方面,我使用:
@Aspect
public class NotificationAspect
{
...
@AfterThrowing(pointcut="@annotation(com.integration.core.meta.NotifyOnFailure)", throwing="ex")
public void executeOnException(JoinPoint joinPoint, ExternalApiExecutionException ex) throws Throwable
{
...
Run Code Online (Sandbox Code Playgroud)
这是官方插件版本的答案更新.为了将Java 8与AspectJ一起使用,可以在此链接上找到官方aspectj maven插件:
http://www.mojohaus.org/aspectj-maven-plugin/usage.html
这是maven存储库的链接:
http://mvnrepository.com/artifact/org.codehaus.mojo/aspectj-maven-plugin/1.8
正如文档所述,使用它的代码是:
<project>
...
<dependencies>
...
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.7</version>
</dependency>
...
</dependencies>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<goals>
<goal>compile</goal> <!-- use this goal to weave all your main classes -->
<goal>test-compile</goal> <!-- use this goal to weave all your test classes -->
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
<build>
...
</project>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
26866 次 |
最近记录: |