我正试图在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>
一些评论:
@PersistenceContext
获取EntityManager
Spring MVC
我的项目具有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>
答案 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