@Transactional methods in @Controller class are not considred as transactional

前端 未结 2 1957
面向向阳花
面向向阳花 2020-12-21 14:31

I noticed that the following is not working in a class marked as a @Controller:

@Autowired
SessionFactory sessionFactory;

@ResponseBody
@Transa         


        
2条回答
  •  心在旅途
    2020-12-21 15:13

    Don't do transactions in your controller. Put them in your service layer classes.

    Separate your code into model-view-controller.

    Yes it is a conspiracy. It enables to you to share code between controllers/views without repeating code. And also stops rollbacks of transactions unnecessarily (for exceptions unrelated to the actual transaction).

    It might seem like more code to begin with, but in the long run it is much more manageable and simpler to develop.

提交回复
热议问题