2

In our web application we have many contextes. In one of them tx:annotation-driven is enabled. As result I have possibility to use @Transactional annotation around the project, except beans created and scanned (@Controller, and related @Service, @Component, etc..) in spring-servlet.xml (for one servlet's app context as was disscussed in Difference between applicationContext.xml and spring-servlet.xml in Spring Framework).

My goals is to additionally enable this feature for beans related to spring-servlet.xml. I can try to do this with adding tx:annotation-driven, but based on this topic spring multiple transaction manager issue such configuration considered not valid.

Could someone suggest in which way I can enable @Transactional for beans from spring-servlet.xml

Community
  • 1
  • 1
fashuser
  • 2,152
  • 3
  • 29
  • 51

1 Answers1

2

I'm not sure whether I properly understand your setup but I assume that you have have a spring web application with multiple servlets; each servlet has it's own spring context and they all have the same parent spring context in common: application-context.xml.

If this is your setup, you should define your PlatformTransactionManager once in application-context.xml; as it's defined in the parent context it's automatically available in every servlet spring context. Then you should be able to use tx:annotation-driven in every servlet spring context and in the parent context as well without any problems as long as they use the same transaction manager.

It's not required to define a transaction manager in every context where you want to use tx:annotation-driven.

Pieter
  • 2,745
  • 14
  • 17