1

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.

Andrew
  • 11
  • 1
  • 2

1 Answers1

1

Have you added:

<context:load-time-weaver/>

to your setup?

Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
  • Adding this appears to invoke a XmlBeanDefinitionStoreException, "The matching wildcard is strict, but no declaration can be found for element 'context:load-time-weaver'", Do I need to add a maven dependency for this to work? – Andrew Sep 03 '11 at 21:06
  • You need `spring-context.jar` (BTW you are using rather outdated Spring version) and you must define `xmlns:context` namespace - see Spring [docs](http://static.springsource.org/spring/docs/2.5.x/reference/xsd-config.html) and my [blog](http://nurkiewicz.blogspot.com/2009/10/yesterday-i-had-pleasure-to-participate.html) – Tomasz Nurkiewicz Sep 03 '11 at 21:17