Wildfly:使用 Spring @Autowired 进行 UserTransaction

Wildfly: Using Spring @Autowired for UserTransaction

在我为一个应用程序从 Jboss AS5 迁移到 Wildfly9 的过程中,我试图在 Wildfly 中加载一个模块:javax.transaction.api 查看 Wildfly article 在 WF8 中加载模块,它说您可能不需要显式加载某些模块,因为它们是隐式加载的。

我正在使用我的 类

 @Autowired
private UserTransaction transaction;

那我定义在applictionContext.xml

<jee:jndi-lookup id="userTransaction" jndi-name="UserTransaction" expected-type="javax.transaction.UserTransaction"/>

在我的 jboss-部署-structure.xml

 <module name="javax.api"/>
  <module name="javax.transaction.api"/>

但是我得到这个错误:

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: 
private javax.transaction.UserTransaction com.mycomp.myapp.EventSender.transaction; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: 
No qualifying bean of type [javax.transaction.UserTransaction] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

我尝试将 jta.jar 添加到 war 的库中,我尝试添加 jta 的依赖项。我尝试添加 javax.transaction 只是为了以防万一,它们都不起作用。我没有收到 ClassNotfoundexceptionClassCastexception。对于ward,一切似乎都那么简单。我不明白这里缺少什么。

"WFLYCTL0080: Failed services" => {"jboss.undertow.deployment.default-server.default-host./myApp" => "org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./myApp: java.lang.RuntimeException: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myAppManager' defined in \"/C:/JAVA/WF9/wildfly-9.0.0.Final/bin/content/myApp-engine-2.0.2-SNAPSHOT.war/WEB-INF/classes/com/mycomp/myApp/myAppManager.class\": Unsatisfied dependency expressed through constructor argument with index 2 of type [com.mycomp.myApp.EventSender]: : Error creating bean with name 'EventSender': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'EventSender': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Caused by: java.lang.RuntimeException: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myAppManager' defined in \"/C:/JAVA/WF9/wildfly-9.0.0.Final/bin/content/myApp-engine-2.0.2-SNAPSHOT.war/WEB-INF/classes/com/mycomp/myApp/myAppManager.class\": Unsatisfied dependency expressed through constructor argument with index 2 of type [com.mycomp.myApp.EventSender]: : Error creating bean with name 'EventSender': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'EventSender': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myAppManager' defined in \"/C:/JAVA/WF9/wildfly-9.0.0.Final/bin/content/myApp-engine-2.0.2-SNAPSHOT.war/WEB-INF/classes/com/mycomp/myApp/myAppManager.class\": Unsatisfied dependency expressed through constructor argument with index 2 of type [com.mycomp.myApp.EventSender]: : Error creating bean with name 'EventSender': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'EventSender': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'EventSender': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransaction': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction Caused by: javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.UserTransaction"}}, "rolled-back" => true

感谢您的帮助。

错误在堆栈跟踪中:

'userTransaction': Invocation of init method failed; nested exception is  javax.naming.NameNotFoundException: UserTransaction

无法创建 bean,因为 JNDI 查找失败。您的应用程序服务器上没有名为 "UserTransaction" 的可用资源。