WFLYEJB0137:仅允许具有 bean 管理的事务划分的会话和消息驱动的 bean 访问 UserTransaction
Posted
技术标签:
【中文标题】WFLYEJB0137:仅允许具有 bean 管理的事务划分的会话和消息驱动的 bean 访问 UserTransaction【英文标题】:WFLYEJB0137: Only session and message-driven beans with bean-managed transaction demarcation are allowed to access UserTransaction 【发布时间】:2015-09-02 21:55:48 【问题描述】:尝试将我的 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)
有人知道发生了什么吗?
【问题讨论】:
【参考方案1】:嗯,这正是异常消息所说的:
只有带有 bean 管理事务的会话和消息驱动 bean 分界允许访问UserTransaction
您不能在 EJB 中使用 UserTransaction
,除非您添加 @TransactionManagement(javax.ejb.TransactionManagementType.BEAN)
。
此外,当您在 WildFly 上使用 JTA、EJB 和 @javax.transaction.Transactional
供您使用的 CDI bean 时,无论如何使用 Spring 事务有什么意义?
【讨论】:
知道为什么在迁移过程中会出现这个问题吗? JBoss 7 没有这个限制吗? @Stéphane 您找到问题的答案了吗?以上是关于WFLYEJB0137:仅允许具有 bean 管理的事务划分的会话和消息驱动的 bean 访问 UserTransaction的主要内容,如果未能解决你的问题,请参考以下文章
配置安全性以通过 WS 访问 EJB -- WFLYEJB0364 连接被拒绝
org.jboss.as.ejb3.component.EJBComponentUnavailableException: WFLYEJB0467: 请求被拒绝,因为容器被挂起
WFLYEJB0029:无法从 ... com.ctc.wstx.exc.WstxEOFException 恢复计时器:序言中出现意外的 EOF