@Transactional in the controller

落爺英雄遲暮 提交于 2021-01-27 17:09:31

问题


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

来源:https://stackoverflow.com/questions/23222970/transactional-in-the-controller

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