0

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>
4

1 に答える 1

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

于 2013-02-23T19:01:03.720 に答える