让eclipse使用Maven编译/编织我的代码

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

但是,当Eclipse编译时(自动自动进行project-> build),它似乎并没有编织Spring事务代码,而我得到了这个错误:

javax.persistence.TransactionRequiredException: no transaction is in progress

这很烦人,因为我只想编写代码,而不希望每次eclipse编译后都手动调用maven编译.

我是否需要编辑AJDT插件的Aspect Path或inPath?为什么Eclipse不只使用Maven进行构建?

我在用:

> Eclipse WTP靛蓝
> Spring 3.0.5.发布
> JDK7和雄猫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>
最佳答案
我正在处理的项目也遇到了同样的问题.简而言之:对于您正在使用的工具集,您需要启用加载时编织或使用Eclipse的早期版本.目前,m2e Eclipse插件以及Aspectj-maven-plugin与Eclipse的最新版本的集成存在问题.最糟糕的是,m2e家伙并不在乎,因为他们不使用AspectJ.

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

> A similar issue
> A mailing list entry describing the issue
> A bug entry for this issue
> An external project started to resolve the issue which appears to have stalled out

相关文章

这篇文章主要介绍了spring的事务传播属性REQUIRED_NESTED的原...
今天小编给大家分享的是一文解析spring中事务的传播机制,相...
这篇文章主要介绍了SpringCloudAlibaba和SpringCloud有什么区...
本篇文章和大家了解一下SpringCloud整合XXL-Job的几个步骤。...
本篇文章和大家了解一下Spring延迟初始化会遇到什么问题。有...
这篇文章主要介绍了怎么使用Spring提供的不同缓存注解实现缓...