自动装配 jaxws:client 时如何解决此 "Could not initialize class org.apache.cxf.common.injection.ResourceInjector" 错误?

How do I resolve this "Could not initialize class org.apache.cxf.common.injection.ResourceInjector" error when autowiring a jaxws:client?

我正在使用 JBoss 7.1.3.Final、Spring 3.2.11.RELEASE、CXF 2.7.15 和 Maven 3.0.3。我正在尝试自动连接通过以下 JAX-WS 插件代码生成的 Web 服务客户端……

<plugin>
    <groupId>org.jvnet.jax-ws-commons</groupId> 
    <artifactId>jaxws-maven-plugin</artifactId>
    <version>2.3</version>
    <executions>
        <execution>
            <goals>
                <goal>wsimport</goal>
            </goals>
            <configuration>
                <target>2.1</target>
                <wsdlDirectory>${basedir}/src/wsdl</wsdlDirectory>
                <sourceDestDir>${basedir}/src/main/java</sourceDestDir>
                <packageName>org.mainco.bsorg</packageName>
            </configuration>
        </execution>
    </executions>
</plugin>

我尝试使用此应用程序上下文代码自动连接我的客户端……

<jaxws:client id="orgWebServiceClient"
              serviceClass="org.mainco.bsorg.OrganizationWebService" 
              address="${wsdl.url}" /> 

这是我的服务 class …

@Service("orgWsdlSvc")
public class OrgWsdlServiceImpl implements OrgWsdlService 
{

    …     
    @Resource(name="orgWebServiceClient")
    private OrganizationWebService m_ows;

然而,当我去部署我的 WAR 文件时,我得到了这个莫名其妙的错误。它甚至没有告诉我 class 是什么导致了 NoClassDefFoundError …

16:06:55,597 ERROR [org.springframework.web.context.ContextLoader] (MSC service thread 1-16) Context initialization failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'orgWebServiceClient': Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.apache.cxf.common.injection.ResourceInjector
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:529) [spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) [spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getObject(AbstractBeanFactory.java:293) [spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) [spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290) [spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191) [spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:618) [spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:934) [spring-context-3.2.11.RELEASE.jar:3.2.11.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) [spring-context-3.2.11.RELEASE.jar:3.2.11.RELEASE]
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:410) [spring-web-3.2.11.RELEASE.jar:3.2.11.RELEASE]
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) [spring-web-3.2.11.RELEASE.jar:3.2.11.RELEASE]
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) [spring-web-3.2.11.RELEASE.jar:3.2.11.RELEASE]
    at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.17.Final.jar:]
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.17.Final.jar:]
    at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:89) [jboss-as-web-7.1.3.Final.jar:7.1.3.Final]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) [classes.jar:1.6.0_65]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) [classes.jar:1.6.0_65]
    at java.lang.Thread.run(Thread.java:695) [classes.jar:1.6.0_65]
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.apache.cxf.common.injection.ResourceInjector
    at org.apache.cxf.bus.extension.ExtensionManagerImpl.loadAndRegister(ExtensionManagerImpl.java:243) [cxf-rt-core-2.7.15.jar:2.7.15]
    at org.apache.cxf.bus.extension.ExtensionManagerImpl.activateAllByType(ExtensionManagerImpl.java:144) [cxf-rt-core-2.7.15.jar:2.7.15]
    at org.apache.cxf.bus.extension.ExtensionManagerBus.<init>(ExtensionManagerBus.java:126) [cxf-rt-core-2.7.15.jar:2.7.15]
    at org.apache.cxf.bus.extension.ExtensionManagerBus.<init>(ExtensionManagerBus.java:138) [cxf-rt-core-2.7.15.jar:2.7.15]
    at org.apache.cxf.bus.spring.SpringBus.<init>(SpringBus.java:46) [cxf-rt-core-2.7.15.jar:2.7.15]
    at org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor.getBusForName(BusWiringBeanFactoryPostProcessor.java:72) [cxf-rt-core-2.7.15.jar:2.7.15]
    at org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor.addDefaultBus(BusWiringBeanFactoryPostProcessor.java:188) [cxf-rt-core-2.7.15.jar:2.7.15]
    at org.apache.cxf.jaxws.spring.JaxWsProxyFactoryBeanDefinitionParser$JAXWSSpringClientProxyFactoryBean.setApplicationContext(JaxWsProxyFactoryBeanDefinitionParser.java:74) [cxf-rt-frontend-jaxws-2.7.15.jar:2.7.15]
    at org.springframework.context.support.ApplicationContextAwareProcessor.invokeAwareInterfaces(ApplicationContextAwareProcessor.java:117) [spring-context-3.2.11.RELEASE.jar:3.2.11.RELEASE]
    at org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:92) [spring-context-3.2.11.RELEASE.jar:3.2.11.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:396) [spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1507) [spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521) [spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
    ... 19 more

我还需要做什么才能在我的 Spring @Service class 中使用我的 Web 服务客户端?

编辑 根据评论,这是我的 WEB-INF/jboss-deployment-structure.xml 文件 ...

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
    <deployment>
        <dependencies>
            <module name="org.joda.time" />
            <module name="org.apache.velocity" />
            <module name="org.bouncycastle" slot="main" export="true" />
            <system>
                <paths>
                    <path name="com/sun/net/ssl/internal/ssl" />
                </paths>
            </system>
        </dependencies>
        <exclude-subsystems>
            <subsystem name="jpa" />
            <subsystem name="jaxr" />
            <subsystem name="jaxrs" />
            <subsystem name="webservices" />
            <subsystem name="weld" /> <!-- Prevent WELD-000070 failure -->
        </exclude-subsystems>
        <exclusions>
            <module name="javaee.api" />
        </exclusions>
    </deployment>
</jboss-deployment-structure>

为了进一步回答评论,这里是请求的输出:

LOG.info(ResourceInjector.class.getClassLoader());
ModuleClassLoader for Module "deployment.myproject.war:main" from Service Module Loader

LOG.info(ResourceInjector.class.getProtectionDomain().getCodeSource().getLocation());
vfs:/content/myproject.war/WEB-INF/lib/cxf-api-2.7.15.jar

LOG.info(ExtensionManagerImpl.class.getClassLoader());
ModuleClassLoader for Module "deployment.myproject.war:main" from Service Module 

LOG.info(ExtensionManagerImpl.class.getProtectionDomain().getCodeSource().getLocation());
vfs:/content/myproject.war/WEB-INF/lib/cxf-rt-core-2.7.15.jar

给定

NoClassDefFoundError: Could not initialize class org.apache.cxf.common.injection.ResourceInjector

我猜测 ResourceInjector 中的静态初始化存在问题,原因是 class 加载问题。

当您查看 source code of ResourceInjector 时,您会注意到它有一个使用 javax.annotation.Resource.

的静态初始化程序

我不熟悉 jboss class 加载甚至一般 jboss,但我看起来你排除了 javaee.api 依赖项。这是否意味着正在加载 ResourceInjector class 的 class 加载程序无法加载 javax.annotation.Resource class?

更新

我以前在 mule 应用程序服务器中遇到过一些 NoClassDefFoundErrors,它总是与应用程序服务器的 class 加载有关。我要做的是在 ´ExtensionManagerImpland inspect/querythis.getClass().getClassLoader()andThread.currentThread().getContextClassLoader( )`。这在过去帮助我解决了这类问题。