Spring编译时编织事务回滚

时间:2013-02-23 11:19:46

标签: spring gwt google-plugin-eclipse compile-time-weaving

我正试图在Aspectj中配置Compile Time Weaving Spring(CTW)。但是,在mode="aspectj"添加tx:annotation-driven后,事务全部失败,结果没有实体存储在数据库中。

以下是我配置的相关部分:

<tx:annotation-driven transaction-manager="transactionManager" mode="aspectj" />
<context:spring-configured />
<context:annotation-config />
<context:component-scan base-package='some.package' />
<aop:aspectj-autoproxy />
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

<bean id='entityManagerFactory' class='org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean'><property name="persistenceUnitName" value="myPU" /> 
<property name="dataSource" ref="dataSource" />
</bean>

我在/ META-INF中也有一个aop.xml(不确定文件是否需要)

<!DOCTYPE aspectj PUBLIC
        "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
<aspectj>
    <weaver>
        <!-- only weave classes in our application-specific packages -->
        <include within="some.package.*" />
    </weaver>
    <aspects>
        <aspect
            name="org.springframework.transaction.aspectj.AnnotationTransactionAspect" />
    </aspects>
</aspectj>

一些评论:

  • 由于我正在工作的环境,我坚持CTW(所以没有LTW) 用。
  • 我使用@PersistenceContext获取EntityManager
  • tx中没有mode =“aspectj”:注释驱动了事务 运行良好
  • 我没有使用Spring MVC
  • 我正在使用GWT 2.5

编辑:

我的项目具有Maven性质,我也必须添加此插件。但我使用EclipseGoogle Plugin运行应用程序。我将项目作为A Web Application (google plugin)运行。我不确定Maven中的代码是否已正确初始化...

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.3</version>
<configuration>
<complianceLevel>1.6</complianceLevel>
<encoding>UTF-8</encoding>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>

1 个答案:

答案 0 :(得分:1)

这是我的pom的相关部分:

<properties>
    <aspectj.version>1.6.11</aspectj.version>
    <aspectj-maven-plugin.version>1.2</aspectj-maven-plugin.version>
</properties>

<dependencies>
     <dependency>
           <groupId>org.aspectj</groupId>
           <artifactId>aspectjrt</artifactId>
           <version>${aspectj.version}</version>
     </dependency>
     <dependency>
           <groupId>org.aspectj</groupId>
           <artifactId>aspectjweaver</artifactId>
           <version>${aspectj.version}</version>
     </dependency>
...
</dependencies>
...

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>aspectj-maven-plugin</artifactId>
            <version>${aspectj-maven-plugin.version}</version>
            <!-- NB: do not use 1.3 or 1.3.x due to MASPECTJ-90 - wait for 1.4 -->
            <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>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                        <goal>test-compile</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <outxml>true</outxml>
                <aspectLibraries>
                    <aspectLibrary>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-aspects</artifactId>
                    </aspectLibrary>
                    <aspectLibrary>
                        <groupId>org.springframework.security</groupId>
                        <artifactId>spring-security-aspects</artifactId>
                    </aspectLibrary>
                </aspectLibraries>
                <source>1.6</source>
                <target>1.6</target>
                <encoding>utf-8</encoding>
            </configuration>
        </plugin>

    </plugins>
</build>

它没有任何问题,没有任何aop.xml