让 eclipse 使用 maven 来编译/编织我的代码
我使用aspectj 进行编译时编织来编织Spring 的事务代码,这样我就可以使用@Transactional
。当我从 Eclipse 内部运行 Maven 编译(使用方面j-maven-插件)时,Eclipse 会同步到 tomcat 服务器,一切顺利。
但是当 Eclipse 编译(项目 -> 自动构建)时,它似乎没有编织 spring 事务代码,并且我收到此错误:
javax.persistence.TransactionRequiredException: no transaction is in progress
这非常烦人,因为我只想编写代码,而不是在每次 eclipse 编译后手动调用 maven 编译。
我需要编辑 AJDT 插件的 Aspect Path 或 inPath 吗?为什么Eclipse不直接使用maven来构建呢?
我正在使用:
- Eclipse WTP Indigo
- Spring 3.0.5.Release
- JDK7 & Tomcat 7
- m2eclipse & AJDT 插件
这些是我的 pom.xml 的相关片段:
<!-- AspectJ -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.6.11</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.6.11</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.aspects</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
<scope>compile</scope>
</dependency>
<!-- Compile time weaving -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<executions>
<execution>
<id>compile</id>
<configuration>
<source>1.6</source>
<target>1.6</target>
<verbose>true</verbose>
<outxml>true</outxml>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
<goals>
<goal>compile</goal>
</goals>
</execution>
<!-- omitted test-compile part -->
</executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.6.11</version>
</dependency>
</dependencies>
</plugin>
I am using compile time weaving with aspectj to weave in Spring's transactional code so I can use @Transactional
. When i run maven compile from inside Eclipse (which uses the aspectj-maven-plugin), eclipse synchronizes to the tomcat server and all goes well.
But when Eclipse compiles (project->build automatically) it appears not to weave the spring transactional code and I get this error:
javax.persistence.TransactionRequiredException: no transaction is in progress
This is very annoying because I just want to code away and not manually call maven compile after eclipse compiles every time.
Do I need to edit the Aspect Path or inPath of the AJDT plugin? Why doesn't Eclipse just use maven to build?
I am using:
- Eclipse WTP Indigo
- Spring 3.0.5.Release
- JDK7 & Tomcat 7
- m2eclipse & AJDT plugins
These are the relevant fragments of my pom.xml:
<!-- AspectJ -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.6.11</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.6.11</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.aspects</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
<scope>compile</scope>
</dependency>
<!-- Compile time weaving -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<executions>
<execution>
<id>compile</id>
<configuration>
<source>1.6</source>
<target>1.6</target>
<verbose>true</verbose>
<outxml>true</outxml>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
<goals>
<goal>compile</goal>
</goals>
</execution>
<!-- omitted test-compile part -->
</executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.6.11</version>
</dependency>
</dependencies>
</plugin>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我正在处理的一个项目也遇到了同样的问题。简而言之:对于您正在使用的工具集,您需要启用加载时编织或使用早期版本的 Eclipse。目前,m2e Eclipse 插件以及aspectj-maven-plugin 与最新版本的Eclipse 集成存在问题。最糟糕的是 m2e 人员并不真正关心,因为他们不使用 AspectJ。
以下是该问题的一些链接:
I'm going through the same issue with a project I'm working on. In short: for the tool set you're using you need to enable load-time weaving or use a prior version of Eclipse. Right now, there is a problem with the m2e Eclipse plugin and the aspectj-maven-plugin integration with recent versions of Eclipse. The worst part is that the m2e guys don't really care because they don't use AspectJ.
Here are some links to the issue:
除了自动编译之外,您还应该检查 JDT 编织插件是否已启用。
窗口|偏好;单击 JDT Weaving 部分 - 验证它当前是否已启用。当您第一次安装该插件时,它会询问您是否要启用此功能,但如果您回答“否”,则可以将其关闭。
In addition to Compile Automatically you should check that the JDT weaving plug-in is enabled.
Window | Preferences; click the JDT Weaving section - verify it is currently enabled. When you first installed the plug-in it asked you if you wanted to enable this, but it could be turned off if you answered "No".