UserTransaction:迁移到 WildFly 8.2.0 和 Java 8 后的 javax.naming.NameNotFoundException [英] UserTransaction: javax.naming.NameNotFoundException after Migration to WildFly 8.2.0 and Java 8

查看:93
本文介绍了UserTransaction:迁移到 WildFly 8.2.0 和 Java 8 后的 javax.naming.NameNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

迁移到 Java 8 和 WildFly 8.2.0 后,我在每个事务中都收到此错误

After migrating to Java 8 and WildFly 8.2.0 I get this error on every Transaction

用户交易:javax.naming.NameNotFoundException:用户交易[根异常是 java.lang.IllegalStateException: JBAS014237: Only具有 bean 管理事务的会话和消息驱动 bean分界被允许访问 UserTransaction] 在org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:140)在org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:81)在 org.jboss.as.naming.NamingContext.lookup(NamingContext.java:202)在 org.jboss.as.naming.NamingContext.lookup(NamingContext.java:179)在org.jboss.as.naming.InitialContext$DefaultInitialContext.lookup(InitialContext.java:235)在 org.jboss.as.naming.NamingContext.lookup(NamingContext.java:188)在 org.jboss.as.naming.NamingContext.lookup(NamingContext.java:184)在 javax.naming.InitialContext.lookup(InitialContext.java:417)[rt.jar:1.8.0_45] 在javax.naming.InitialContext.lookup(InitialContext.java:417)[rt.jar:1.8.0_45]

UserTransaction: javax.naming.NameNotFoundException: UserTransaction [Root exception is java.lang.IllegalStateException: JBAS014237: 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:140) at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:81) at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:202) at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:179) at org.jboss.as.naming.InitialContext$DefaultInitialContext.lookup(InitialContext.java:235) at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:188) at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:184) at javax.naming.InitialContext.lookup(InitialContext.java:417) [rt.jar:1.8.0_45] at javax.naming.InitialContext.lookup(InitialContext.java:417) [rt.jar:1.8.0_45]

Bean 有注解 @TransactionManagement(TransactionManagementType.BEAN)

这是异常发生的地方:

final javax.naming.Context tmpNamingContext = new javax.naming.InitialContext();
                    userTransaction = ((UserTransaction) tmpNamingContext.lookup("java:jboss/UserTransaction"));

我不知道这里发生了什么,也找不到任何好的解决方案.

I don't know what is happening here and cannot found any good solution.

请帮忙.

推荐答案

使用注释 @Resource 而不是通过 JNDI Name 获取 UserTransaction 是解决方案.UserTransaction 在 WildFly 8.2.0 中不再存在,在 JBoss 中已经设置.

Get the UserTransaction with the annotation @Resource instead of through the JNDI Name was the solution. UserTransaction is no more in WildFly 8.2.0, in JBoss it was set already.

这解决了问题.

这篇关于UserTransaction:迁移到 WildFly 8.2.0 和 Java 8 后的 javax.naming.NameNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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