AspectJ Load Time Weaving with Spring Transaction Manager and Maven

こ雲淡風輕ζ 提交于 2019-12-08 07:24:51

问题


I'm attempting to enable load time weaving with Spring's transaction manager but without too much luck. Currently I'm just trying to run a simple em.persist() in a @Transactional method but it does not appear to running a transaction as seen through: TransactionSynchronizationManager.isActualTransactionActive()

My application context file contains :

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="TEST-pu"/>
    </bean>
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>
    <tx:annotation-driven transaction-manager="transactionManager" mode="aspectj" proxy-target-class="true"/>

And my pom.xml contains:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-agent</artifactId>
    <version>2.5.4</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aspects</artifactId>
    <version>3.0.5.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.aspectj</groupId>
    <artifactId>aspectjrt</artifactId>
    <version>1.6.10</version>
</dependency>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.4</version>
    <configuration>
        <forkMode>once</forkMode>
        <argLine>
            -javaagent:${settings.localRepository}/org/springframework/spring-agent/2.5.4/spring-agent-2.5.4.jar
        </argLine>
        <useSystemClassloader>true</useSystemClassloader>
    </configuration>
</plugin> 

It would appear as if there is some issue with the setup and while I have come across quite a few examples of how to implement AspectJ / Load time weaving they all seem to be using Eclipse plugins which 1) I am trying to avoid using any sort of plugins and 2) I am using Intellij. Any help would be much appreciated.

Thanks.


回答1:


Have you added:

<context:load-time-weaver/>

to your setup?



来源:https://stackoverflow.com/questions/7295686/aspectj-load-time-weaving-with-spring-transaction-manager-and-maven

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!