【问题标题】:Spring compile time weaving transaction rollbackSpring编译时编织事务回滚
【发布时间】:2013-02-23 11:19:45
【问题描述】:

我正在尝试在Spring 中配置Aspectj Compile Time Weaving(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:annotation-driven 交易中没有 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>

【问题讨论】:

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


    【解决方案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

    【讨论】:

    • 基本一样。问题是我使用 GWT 的开发模式,这个 aspectj-maven-plugin 可能没有编译。当我使用 google 插件将项目作为 Web 应用程序运行时,这可能会被跳过...但是如何使用 CTW 编织然后使用 GWT?
    • @GTT4Ever:如果 GWT 是问题,那我帮不了你,对不起。
    • 我认为 GWT 不是问题所在。我可以做任何测试来进一步了解这个问题吗?
    • 编写一个没有 GWT 的小示例应用程序
    • 我认为这个问题与stackoverflow.com/questions/15047071/…有关。我在那里提供了一个小示例应用程序。
    猜你喜欢
    • 2013-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-08
    相关资源
    最近更新 更多