我正在尝试Aspectj
Compile Time Weaving
在Spring
. 但是,在添加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
性质,我也必须添加这个插件。但我使用Eclipse
和运行应用程序Google 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>