Java Spring JTA 配置 - 如何设置 TransactionManager?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1783540/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 22:37:17  来源:igfitidea点击:

Spring JTA configuration - how to set TransactionManager?

javaspringjbossjtaspring-transactions

提问by Marcus Leon

We configure our Spring transaction in Spring config as:

我们在 Spring config 中将 Spring 事务配置为:

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

我认为这意味着 Spring 将自动发现底层 JTA 实现。因此,当我们启动 JBoss 时,我们会在 Spring 搜索时看到这些消息:

[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 ManagerJTA implementation so we avoid all these stack traces in the logs? (I'd prefer not to just change the Log4J logging levels)

问题是 - 我们如何编辑我们的<tx:jta-transaction-manager/>标签来显式配置java:/Transaction ManagerJTA 实现,从而避免日志中的所有这些堆栈跟踪?(我不想只更改 Log4J 日志记录级别)



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

更新:我<tx:jta-transaction-manager/>用下面的配置替换了它似乎可以工作..我猜这没问题吗?

<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
    <property name="transactionManagerName" value="java:/TransactionManager"/>
</bean>

采纳答案by Henning

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.

是的,没关系。您看到的堆栈跟踪也没有问题:<tx:jta-transaction-manager/>尝试从许多不同的标准位置获取事务管理器;对于每次失败的 JNDI 查找,您都会看到javax.naming.NameNotFoundException.

java:/TransactionManageris 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.

java:/TransactionManager是 JBoss 默认绑定的地方;其他 servlet 容器将默认为java:/comp/TransactionManager,我认为这应该是 TM 的“标准”位置。

From the Spring reference documentation:

Spring 参考文档

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 JtaTransactionManageras default fallback.

对于标准场景,包括 WebLogic、WebSphere 和 OC4J,请考虑使用方便的 <tx:jta-transaction-manager/>配置元素。这将自动检测底层服务器并选择可用于平台的最佳事务管理器。这意味着您不必显式配置特定于服务器的适配器类(如以下部分所述);他们宁愿自动选择,标准JtaTransactionManager作为默认后备。

回答by Pascal Thivent

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

一个常见的“错误”是将诸如jta.jar和/或jbossall-client.jar在您部署的 J2EE 组件中的东西捆绑在一起。如果是这种情况,请仔细检查并删除它们。