9

メソッドをトランザクション対応にするために使用したいのですspring-aspectsが、Spring AOP を使用しません (Spring AOP は: で問題なく動作します<tx:annotation-driven/>)。プロジェクトの管理に Maven を使用しています。

私のプロジェクトクラスでコンパイル時の織りを行う方法はありますかTransactional? Mojo の AspectJ Maven Pluginを使用しようとしましたが、良い結果は得られませんでした。

助けてください。

4

3 に答える 3

5

I figured it out. Maven plugin works fine but the problem was with my spring config: I had:

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>

What I needed was:

<bean id="transactionManager"   class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean class="org.springframework.transaction.aspectj.AnnotationTransactionAspect" factory-method="aspectOf">
    <property name="transactionManager" ref="transactionManager"/>
</bean>

Now it works fine. And performace of my @Transactional methods improved and that what I was aming for.

Here is my maven aspectj plugin config:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.3</version>
    <configuration>
        <aspectLibraries>
            <aspectLibrary>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aspects</artifactId>
            </aspectLibrary>
       </aspectLibraries>
        <source>1.5</source>
        <showWeaveInfo>true</showWeaveInfo>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>compile</goal>
            </goals>
        </execution>
    </executions>
</plugin>

hope this helps someone.

于 2010-02-06T20:40:51.237 に答える
1

これは、Java構成で同じことを行う方法について私が提供した回答へのリンクです。

Spring @Transactional は、動的 Jdk プロキシとアスペクトの両方として適用されます。

それが役に立てば幸い

于 2015-11-26T15:29:10.203 に答える