Spring JTA TransactionManager config: Supporting both Tomcat and JBoss

后端 未结 5 1032
广开言路
广开言路 2021-02-06 01:19

I have a web application using JPA and JTA with Spring. I would like to support both JBoss and Tomcat. When running on JBoss, I\'d like to use JBoss\' own TransactionManager, an

5条回答
  •  终归单人心
    2021-02-06 01:55

    Just adding my experience here so I don't have to re-suffer the experience again.

    As bmatthews68, Chochos and these posters have said, use in your Spring bean file; it definitely provides the appropriate level of abstraction and there's no need to do anything extra on the Spring side.

    As for Tomcat, I declared in the default/shared conf/context.xml file, which binds to java:comp/UserTransaction. As this is one of the places searched for by Spring, you shouldn't need to do anything else.

    One gotcha though: if like me you use Maven, make sure you exclude any dependencies on the javax.transaction:jta jar or set the scope to provided. Otherwise you will experience classloader issues.

提交回复
热议问题