2

First of all I want to mention that I fully agree to only make the service layer transactional, but sometimes world is not perfect, and right now I´m in the middle of that situation. Basically I have been assigned into a wonderful project with a legacy code of 4+ years. The thing is that the developers did not follow any pattern where to introduce the bussines logic so you can image multiples services call from the controller and after that some extra call to private method into the controller. No budget to refactor, and we have many issues with ACID so the only solution that I found is make the controllers transactional and at least then have a full rollback if something in the middle of the request/response go wrong. The problem is that I cannot make it works. I will describe you my configuration to see if you can help me out guys. I have a DispatcherServlet that invoke webmvc-config.xml where I have the declaration of the controllers

     <context:component-scan base-package="com.greenvalley.etendering.web.controller**" use-default-filters="false">
         <context:include-filter expression="org.springframework.stereotype.Controller" type="annotation"/>
    </context:component-scan>

Then the contextConfiguration invoke my applicationContext.xml where I have all the rest of my Spring configuration.

After read so many tickets I tried many convination, for example try to declare again my controllers into the application context.

  <tx:annotation-driven mode="aspectj"/> I tried with proxy as well

<context:component-scan base-package="com.greenvalley.etendering.web.controller.*" />

But still nothing.

In the configuration of my txManager I dont do nothing fancy, just add the reference to the entityManagerFactory and that´s it

<tx:annotation-driven transaction-manager="transactionManager"/>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>

In my controller I add the @Transactional, but nothing every time that I made a request to the @transactional class/method I dont see that the breakpoint into JpaTransactionalManager doBegin method stop

any suggestion please!

Regards

paul
  • 12,873
  • 23
  • 91
  • 153
  • Try having the controllers in the applicationContext, use `` and add CGLIB to the classpath – geoand Apr 22 '14 at 14:58
  • Is tx:annotation-driven in the same Spring context that your controller beans loaded? tx:annotation-driven is a bean post processor, so it will only decorate @Transactional method on beans in the same context. – MarkOfHall Apr 22 '14 at 15:01
  • I try the first solution but does not works and throw an exception my other bean services. About the second solution I try the controller declaration in the applicationContext, and in the xml where I configure the entityManagerFactory and TransactionManager and nothing. No transaction works on controller – paul Apr 22 '14 at 15:57
  • What do you mean by throwing an exception on your other bean services? You cannot combine cglib and jdk proxying methods. If you choose proxy-target-class="true", all your proxied classes must have nonparametric constructor and must not be final, is that the exception you get? – Libor Subcik Apr 23 '14 at 08:10

0 Answers0