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

标签 java spring wildfly

尝试将我的 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/

相关文章:

java - 未加载 Spring 上下文

java - Spring 更改 Content-Type 的 header ?

java - tomcat运行但404无错误返回

jboss - 无法将 postgres 与 keycloak 一起使用

java - 如何在 Wildfly 11 上的异步事件中保留 CDI 上下文?

java - 相当于什么button3_Click(sender, e);在Java中?

java - Tomcat 中相同的 tensorflow 模型推理从简单的 Java 应用程序中得到不同的结果

java - JDK1.6 中来自 ManagementFactory 的托管 Mbean - NotCompliantMBeanException :

java - 等待/通知 vs sleep /中断 vs ReentrantLock.Condition

java - 焊接-001408 : Unsatisfied dependencies for repositories from Spring Data