Aspectj
Compile Time Weaving
で(CTW) を構成しようとしています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>