Spring JTA 配置 - 如何设置 TransactionManager? [英] Spring JTA configuration - how to set TransactionManager?

查看:43
本文介绍了Spring JTA 配置 - 如何设置 TransactionManager?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

We configure our Spring transaction in Spring config as:

<tx:jta-transaction-manager/>

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

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

然后最终看到:

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

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

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)

更新:我用下面的配置替换了 <tx:jta-transaction-manager/> 并且它似乎有效..我猜这是好吗?

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>

推荐答案

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

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 是 JBoss 默认绑定的地方;其他 servlet 容器将默认为 java:/comp/TransactionManager,我认为这应该是 TM 的标准"位置.

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.

来自 Spring 参考文档:

对于标准场景,包括WebLogic、WebSphere 和 OC4J,请考虑使用方便配置元素.这会自动检测底层服务器并选择最佳交易平台可用的经理.这意味着您将不必配置特定于服务器的适配器类(如下所述节)明确;他们宁愿被自动选择,与标准 JtaTransactionManager 作为默认回退.

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.

这篇关于Spring JTA 配置 - 如何设置 TransactionManager?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆