我如何解决此“无法初始化org.apache.cxf.common.injection.ResourceInjector类".自动装配jaxws:client时出错? [英] How do I resolve this "Could not initialize class org.apache.cxf.common.injection.ResourceInjector" error when autowiring a jaxws:client?

查看:304
本文介绍了我如何解决此“无法初始化org.apache.cxf.common.injection.ResourceInjector类".自动装配jaxws:client时出错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I’m using JBoss 7.1.3.Final, Spring 3.2.11.RELEASE, CXF 2.7.15 and Maven 3.0.3. I’m trying to autowire a web services client that is generated through the below JAX-WS plugin code …

<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>

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

I attempt to autowire my client using this application context code …

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

这是我的服务等级……

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

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

但是,当我去部署我的WAR文件时,出现了这个莫名其妙的错误.它甚至没有告诉我该类是什么引起了NoClassDefFoundError…

However, when I go to deploy my WAR file, I get this baffling error. It doesn’t even tell me what the class is causing the 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$1.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类中使用Web服务客户端还需要做些什么?

What else do I need to do to use my web service client within my Spring @Service class?

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

Edit Per the comment, here is my WEB-INF/jboss-deployment-structure.xml file ...

<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>

要进一步回答评论,请参见以下输出:

To further answer the comments, here is the output requested:

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:无法初始化类 org.apache.cxf.common.injection.ResourceInjector

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

我想由于类加载问题,ResourceInjector中的静态初始化存在问题.

I would guess that there's a problem with the static initialization in ResourceInjector due to class loading issues.

当您查看

When you look at the source code of ResourceInjector you'll notice that it has a static initializer that uses javax.annotation.Resource.

我对jboss类的加载甚至是jboss都不熟悉,但是看起来您不包含javaee.api依赖项.难道这意味着正在加载ResourceInjector类的类加载器无法加载javax.annotation.Resource类吗?

I'm am not familiar with jboss class loading or even jboss in general, but I looks like you're excluding javaee.api dependencies. Could this by any chance mean that the class loader that's loading the ResourceInjector class isn't able to load the javax.annotation.Resource class?

更新

我之前在m子应用程序服务器中遇到过一些NoClassDefFoundErrors,它总是与应用程序服务器的类加载有关.我要找出问题的方法是在´ExtensionManagerImpl and inspect/query this.getClass().getClassLoader()and Thread.currentThread().getContextClassLoader()`中的第243行打开调试器.过去这帮助我解决了这类问题.

I've encountered some NoClassDefFoundErrors before in a mule application server and it always had something to do with the class loading of the application server. What I would do to track down the problem is open a debugger at line 243 in ´ExtensionManagerImpland inspect/querythis.getClass().getClassLoader()andThread.currentThread().getContextClassLoader()`. This has helped me in the past to solve these kind of problems.

这篇关于我如何解决此“无法初始化org.apache.cxf.common.injection.ResourceInjector类".自动装配jaxws:client时出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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