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
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?