UserTransaction: javax.naming.NameNotFoundException after Migration to WildFly 8.2.0 and Java 8

别说谁变了你拦得住时间么 提交于 2019-12-20 04:12:39

问题


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

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]

The Bean has the annotation @TransactionManagement(TransactionManagementType.BEAN)

This is where the exception happens:

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.

Please help.


回答1:


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.

This solves the issue.



来源:https://stackoverflow.com/questions/31538533/usertransaction-javax-naming-namenotfoundexception-after-migration-to-wildfly-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!