views:

197

answers:

2

Hi.

I want to use spring-aspects to make my methods transactional but without using spring AOP (spring AOP works just fine with: <tx:annotation-driven/> ). I'm using maven to manage my project.

Is there a way to do compile time weaving on my project classes so "they are Transactional". I was trying to use this plugin: http://mojo.codehaus.org/aspectj-maven-plugin/ but without any good results.

Please help.

A: 

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.

Monku
A: 

Thanks. This helps. Also note that you may need to follow the advise of: http://forum.springsource.org/showthread.php?t=85594

Jim