【发布时间】: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 的性质,我也必须添加这个插件。但我使用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>
【问题讨论】:
标签: spring gwt google-plugin-eclipse compile-time-weaving