java 没有可用的 JTA UserTransaction - 指定“userTransaction”或“userTransactionName”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3811246/
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-10-30 03:28:40  来源:igfitidea点击:

No JTA UserTransaction available - specify either 'userTransaction' or 'userTransactionName'

javaspringjboss5.x

提问by Chir

I have encountered a strange problem with spring transaction. My application uses Spring with EJBs. The EJBs also invoke Spring service classes annotated with @Transaction. I have used Spring JtaTransactionManagerfor transaction management. The application is packaged as an EAR file and is deployed on jboss5.0 and it works fine. But when I instruct jboss to use separate classloader for each EAR application, spring initialization gives error.

我在spring事务中遇到了一个奇怪的问题。我的应用程序使用带有 EJB 的 Spring。EJB 还调用带有@Transaction. 我使用 SpringJtaTransactionManager进行事务管理。应用打包为EAR文件,部署在jboss5.0上,运行正常。但是当我指示 jboss 为每个 EAR 应用程序使用单独的类加载器时,spring 初始化会出错。

org.springframework.beans.factory.BeanCreationException: Error creating bean
   with name 'transactionManager' defined in ServletContext resource 
   [/WEB-INF/applicationContext.xml]: Invocation of init method failed; 
nested exception is java.lang.IllegalStateException: No JTA UserTransaction 
   available - specify either 'userTransaction' or 'userTransactionName' or 
   'transactionManager' or 'transactionManagerName'

Why initialization of Spring is not successful?

为什么Spring初始化不成功?

Thanks

谢谢

回答by NiNiCkNaMe

try adding

尝试添加

@EnableTransactionManagement

on a configuration class where you hold your config bean

在您保存配置 bean 的配置类上

that worked for me when i had that issue , maybe you will need other platform specific implementation of the transaction manager , but this is a good place to start.

当我遇到这个问题时,这对我有用,也许您需要事务管理器的其他平台特定实现,但这是一个很好的起点。

@Bean
public PlatformTransactionManager transactionManager() {
    JpaTransactionManager txManager = new JpaTransactionManager();
    txManager.setEntityManagerFactory(entityManagerFactory());
    return txManager;
}