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

前端 未结 2 1949
面向向阳花
面向向阳花 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:23

    Probably you have two application contexts here: main Spring context loaded by ContextLoaderListener and a child context loaded by DispatcherServlet. You need to put in the configuration loaded by the child context too. If you show us your web.xml file maybe I can help you more.

    Anyway, as @NimChimpsky says, is usually not a good practice to manage transactions in your controller layer.

提交回复
热议问题