Spring JTA configuration - how to set TransactionManager?
Asked Answered
G

2

13

We configure our Spring transaction in Spring config as:

<tx:jta-transaction-manager/>

I gather this means that Spring will automatically discover the underlying JTA implementation. So when we start up JBoss we see these messages while Spring searches:

[JtaTransactionManager] [ ] No JTA TransactionManager found at fallback JNDI location [java:comp/Tran
sactionManager]
javax.naming.NameNotFoundException: TransactionManager not bound
<<Big stack trace>>    
<<More of the same>>

And then eventually see:

[JtaTransactionManager] [ ] JTA TransactionManager found at fallback JNDI location [java:/Transaction
Manager]
[JtaTransactionManager] [ ] Using JTA UserTransaction: org.jboss.tm.usertx.client.ServerVMClientUserT
ransaction@1f78dde

Question is - how can we edit our <tx:jta-transaction-manager/> tag to explicitly configure the java:/Transaction Manager JTA implementation so we avoid all these stack traces in the logs? (I'd prefer not to just change the Log4J logging levels)


Update: I replaced <tx:jta-transaction-manager/> with the below config and it seems to work.. i'm guessing this is alright?

<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
    <property name="transactionManagerName" value="java:/TransactionManager"/>
</bean>
Grouty answered 23/11, 2009 at 14:41 Comment(1)
Generally speaking, it's always good to provide as much informations as possible on your context like the version of JBoss, the kind of application you are deplpoying, etc. I'm not saying this will solve the question here, but it may help.Fir
W
13

Yes, that's alright. The stack trace you were seeing was also alright: <tx:jta-transaction-manager/> tries to acquire the transaction manager from a number of different standard locations; for every failed JNDI lookup, you'll see the javax.naming.NameNotFoundException.

java:/TransactionManager is where JBoss binds to by default; other servlet containers will default to java:/comp/TransactionManager, which I think is supposed to be the "standard" location for the TM.

From the Spring reference documentation:

For standard scenarios, including WebLogic, WebSphere and OC4J, consider using the convenient <tx:jta-transaction-manager/> configuration element. This will automatically detect the underlying server and choose the best transaction manager available for the platform. This means that you won't have to configure server-specific adapter classes (as discussed in the following sections) explicitly; they will rather be chosen automatically, with the standard JtaTransactionManager as default fallback.

Wages answered 23/11, 2009 at 15:55 Comment(0)
F
4

A common "mistake" is to bundle things like jta.jar and/or jbossall-client.jar in the J2EE component you deploy. Double check please and remove them if this is the case.

Fir answered 23/11, 2009 at 14:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.