gpt4 book ai didi

java - WFLYEJB0137 : Only session and message-driven beans with bean-managed transaction demarcation are allowed to access UserTransaction

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:43:06 28 4
gpt4 key购买 nike

尝试将我的 Ejb 从 JBoss 7.1.1 迁移到 Wildfly,但我卡在了以下错误:

Caused by: org.springframework.transaction.TransactionSystemException: JTA UserTransaction is not available at JNDI location [java:jboss/UserTransaction]; nested exception is javax.naming.NameNotFoundException: UserTransaction [Root exception is java.lang.IllegalStateException: WFLYEJB0137: Only session and message-driven beans with bean-managed transaction demarcation are allowed to access UserTransaction]
at org.springframework.transaction.jta.JtaTransactionManager.lookupUserTransaction(JtaTransactionManager.java:574)
at org.springframework.transaction.jta.JtaTransactionManager.initUserTransactionAndTransactionManager(JtaTransactionManager.java:448)
at org.springframework.transaction.jta.JtaTransactionManager.afterPropertiesSet(JtaTransactionManager.java:435)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
... 183 more
Caused by: javax.naming.NameNotFoundException: UserTransaction [Root exception is java.lang.IllegalStateException: WFLYEJB0137: Only session and message-driven beans with bean-managed transaction demarcation are allowed to access UserTransaction]
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:153)
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:83)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:207)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:184)
at org.jboss.as.naming.InitialContext$DefaultInitialContext.lookup(InitialContext.java:237)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:193)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:189)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:155)
at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:179)
at org.springframework.transaction.jta.JtaTransactionManager.lookupUserTransaction(JtaTransactionManager.java:571)
... 187 more
Caused by: java.lang.IllegalStateException: WFLYEJB0137: Only session and message-driven beans with bean-managed transaction demarcation are allowed to access UserTransaction
at org.jboss.as.ejb3.component.allowedmethods.AllowedMethodsInformation.realCheckPermission(AllowedMethodsInformation.java:138)
at org.jboss.as.ejb3.component.allowedmethods.AllowedMethodsInformation.checkAllowed(AllowedMethodsInformation.java:112)
at org.jboss.as.ejb3.subsystem.EJB3UserTransactionAccessControlService$1.authorizeAccess(EJB3UserTransactionAccessControlService.java:53)
at org.jboss.as.txn.service.UserTransactionAccessControlService.authorizeAccess(UserTransactionAccessControlService.java:83)
at org.jboss.as.txn.service.UserTransactionBindingService$1.getReference(UserTransactionBindingService.java:71)
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:143)
... 200 more

Spring 4 和事务管理器 bean 设置为 JTA,如下所示:

@Bean
public PlatformTransactionManager transactionManager(JndiTemplate jnditemplate) {
// Get JTA from Java EE server
final JtaTransactionManager jtaTransactionManager = new JtaTransactionManager();
jtaTransactionManager.setTransactionManagerName("java:jboss/TransactionManager");
jtaTransactionManager.setUserTransactionName("java:jboss/UserTransaction");
jtaTransactionManager.setNestedTransactionAllowed(true);
jtaTransactionManager.setJndiTemplate(jnditemplate);

return jtaTransactionManager;
}

Ejb 使用以下注解

@Singleton
@Interceptors(SpringBeanAutowiringInterceptor.class)
@ConcurrencyManagement(ConcurrencyManagementType.BEAN)

有人知道发生了什么事吗?

最佳答案

嗯,这就是异常消息所说的:

Only session and message-driven beans with bean-managed transaction demarcation are allowed to access UserTransaction

您不能在 EJB 中使用 UserTransaction,除非您添加 @TransactionManagement(javax.ejb.TransactionManagementType.BEAN)

此外,当您在 WildFly 上使用 JTA、EJB 和 @javax.transaction.Transactional 来处理 CDI bean 时,无论如何使用 Spring 事务有什么意义?

关于java - WFLYEJB0137 : Only session and message-driven beans with bean-managed transaction demarcation are allowed to access UserTransaction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30895400/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com