3

我正在使用带有 aspectj 的编译时编织来编织 Spring 的事务代码,因此我可以使用@Transactional. 当我从 Eclipse(它使用 aspectj-maven-plugin)内部运行 maven compile 时,eclipse 会同步到 tomcat 服务器并且一切顺利。

但是当 Eclipse 编译(项目-> 自动构建)时,它似乎没有编织 spring 事务代码,我得到了这个错误:

javax.persistence.TransactionRequiredException: no transaction is in progress

这很烦人,因为我只想编写代码而不是在每次 Eclipse 编译后手动调用 maven compile。

我需要编辑 AJDT 插件的 Aspect Path 或 inPath 吗?为什么 Eclipse 不直接使用 maven 构建?


我在用:

  • Eclipse WTP 靛蓝
  • 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>
4

2 回答 2

3

我正在处理的一个项目也遇到了同样的问题。简而言之:对于您正在使用的工具集,您需要启用加载时编织或使用早期版本的 Eclipse。现在,m2e Eclipse 插件和 aspectj-maven-plugin 与最新版本的 Eclipse 集成存在问题。最糟糕的是,m2e 的人并不真正关心,因为他们不使用 AspectJ。

以下是该问题的一些链接:

于 2011-08-25T02:59:35.883 回答
0

除了自动编译之外,您还应该检查是否启用了 JDT 编织插件。

窗口 | 优先; 单击 JDT Weaving 部分 - 验证它当前已启用。当您第一次安装插件时,它会询问您是否要启用此功能,但如果您回答“否”,它可能会被关闭。确保此屏幕显示 JDT Weaving 已启用

于 2011-08-25T02:23:12.030 回答