0

I'm trying to get Aspectj Compile Time Weaving(CTW) configured in Spring. However after adding mode="aspectj" to the tx:annotation-driven, the transactions all fail and no entities are stored in the database as a result.

Here is the relevant part of my configuration:

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

I also have a aop.xml in /META-INF (not sure the file is needed though)

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

Some remarks:

  • I am stuck to CTW (so no LTW) because of the environment I'm working with.
  • I use @PersistenceContext to get the EntityManager
  • Without mode="aspectj" in tx:annotation-driven the transactions run fine
  • I'm not using Spring MVC
  • I'm using GWT 2.5

edit:

My project has a Maven nature, and I had to add this plugin too. But I run the application using Eclipse and the Google Plugin. I run the project as A Web Application (google plugin). I'm not sure if this code in Maven is properly initialised...

<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>
Community
  • 1
  • 1
Vjeetje
  • 5,314
  • 5
  • 35
  • 57

1 Answers1

1

This are the relevant parts of my 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>

It works without any problems and without any aop.xml

Ralph
  • 118,862
  • 56
  • 287
  • 383
  • That's basicly the same. The problem is I use GWT's development mode and this aspectj-maven-plugin isn't probably compiled. When I run the project as a Webapplication using the google plugin this is probably skipped... But how can I use CTW weaving then using GWT? – Vjeetje Feb 23 '13 at 19:06
  • @GTT4Ever: If GWT is the problem, then I can not help you, sorry. – Ralph Feb 23 '13 at 19:43
  • I don't think GWT is the problem. Is there any test I can do to get further insights in this problem? – Vjeetje Feb 25 '13 at 13:41
  • Write a small sample application wihtout GWT – Ralph Feb 25 '13 at 14:03
  • I think this problem is related to http://stackoverflow.com/questions/15047071/compile-time-weaving-null-pointer-exception . I supplied a small sample application there. – Vjeetje Feb 26 '13 at 20:42
  • @Arjan: you are the first one how noticed it. ;-) I corrected it. – Ralph Jul 15 '13 at 14:02