Spring @Transactional not working

后端 未结 1 1186
面向向阳花
面向向阳花 2020-11-27 03:25

I previously had a post on this issue that was resolved. However since rebuilding the project with auto wired beans and less XML configuration I find I am revisiting this is

相关标签:
1条回答
  • 2020-11-27 03:40

    The reason that moving the context:component-scan tags to the application context xml fixed the transactional behavior is: <tx:annotation-driven /> is a post-processor that wraps @Transactional annotated bean methods with an AOP method interceptor which handles transactional behavior. Spring post-processors, only operate on the specific application context they are defined in.

    In your case, you have defined the <tx:annotation-driven /> post-processor in the application context, while the beans annotated with @Transactional are in the servlet application context. Thus, the <tx:annotation-driven /> post-processor only operated on the application context beans, not the servlet context beans. When the context:component-scan tags were moved to the application context, then the <tx:annotation-driven /> post-processor wrapped their transactional methods appropriately.

    Hope that makes some sense.

    [Edit]

    What is the difference between the Application Context and a Servlet Context?

    What is a Spring post-processor and how does it work?

    What is AOP in Spring?

    0 讨论(0)
提交回复
热议问题