springcxfjax-wsautowiredjaxws-maven-plugin

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


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}" /> 

and this in my service class …

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

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

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

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

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

Solution

  • Given

    NoClassDefFoundError: Could not initialize class org.apache.cxf.common.injection.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.

    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?

    UPDATE

    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.