1 Reply Latest reply on Jan 15, 2014 4:07 AM by Alessio Soldano

    How to autowire spring beans in JBoss 7.1.1 with CXF?

    Paulo Vivacqua Newbie

      We are trying to implement a Web Services using jbossws-cxf-4.1.1.Final with spring 3.0.7.RELEASE on a JBoss AS 7.1.1. We installed the CXF and Spring modules on the server using the ant task provided in the distribution. When we run our Webservice the autowired Spring beans don´t get injected and we get a null pointer exception.

       

      Searching the web and found 2 workarounds. Unfortunately none of them worked.

       

      The first approach was to move dependency injection to @PostConstruct method as suggested here http://stackoverflow.com/questions/5350723/jboss-6-spring-3-0-5-jax-ws-cxf and here https://jira.springsource.org/browse/SPR-9786

       

      @PostConstruct
      public void init() {
          SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
      }
      

       

      The second workaround was  wiring JAX-WS endpoints to extend SpringBeanAutowiringSupport, but that did not work either.

       

      @Component
      @WebService(name = "TesteImpl", 
        serviceName = "Teste", 
        targetNamespace = "http://gid.ws.nds.teste/", 
        endpointInterface = "br.com.gid.ws.interfaces.Teste")
      public class TesteImpl extends SpringBeanAutowiringSupport implements Teste {
      
      
        @Autowired
        @Qualifier("perfilMediator")
        private PerfilMediator perfilMediator;
      
        public Response add(Request request) {
      
        Response response = perfilMediator.add(request);
        }
      }
      
      

       

      The stackTrace

      
      
      
      
      13:31:47,984 WARN  [org.jboss.ws.common] (http-localhost-127.0.0.1-8080-1) JBWS022061: Method invocation failed with exception: java.lang.reflect.InvocationTargetException
      
      
      
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.6.0_45]
      
      
      
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [rt.jar:1.6.0_45]
      
      
      
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [rt.jar:1.6.0_45]
      
      
      
      at java.lang.reflect.Method.invoke(Method.java:597) [rt.jar:1.6.0_45]
      
      
      
      at org.jboss.ws.common.invocation.AbstractInvocationHandlerJSE.invoke(AbstractInvocationHandlerJSE.java:108) [jbossws-common.jar:2.1.1.Final]
      
      
      
      at org.jboss.wsf.stack.cxf.JBossWSInvoker.performInvocation(JBossWSInvoker.java:149) [jbossws-cxf-server.jar:4.1.1.Final]
      
      
      
      at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96) [cxf-api.jar:2.6.4]
      
      
      
      at org.apache.cxf.jaxws.AbstractJAXWSMethodInvoker.invoke(AbstractJAXWSMethodInvoker.java:178) [cxf-rt-frontend-jaxws.jar:2.6.4]
      
      
      
      at org.apache.cxf.jaxws.JAXWSMethodInvoker.invoke(JAXWSMethodInvoker.java:64) [cxf-rt-frontend-jaxws.jar:2.6.4]
      
      
      
      at org.jboss.wsf.stack.cxf.JBossWSInvoker.invoke(JBossWSInvoker.java:129) [jbossws-cxf-server.jar:4.1.1.Final]
      
      
      
      at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58) [cxf-api.jar:2.6.4]
      
      
      
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439) [rt.jar:1.6.0_45]
      
      
      
      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) [rt.jar:1.6.0_45]
      
      
      
      at java.util.concurrent.FutureTask.run(FutureTask.java:138) [rt.jar:1.6.0_45]
      
      
      
      at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37) [cxf-api.jar:2.6.4]
      
      
      
      at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:107) [cxf-api.jar:2.6.4]
      
      
      
      at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262) [cxf-api.jar:2.6.4]
      
      
      
      at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) [cxf-api.jar:2.6.4]
      
      
      
      at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:236) [cxf-rt-transports-http.jar:2.6.4]
      
      
      
      at org.jboss.wsf.stack.cxf.RequestHandlerImpl.handleHttpRequest(RequestHandlerImpl.java:95) [jbossws-cxf-server.jar:4.1.1.Final]
      
      
      
      at org.jboss.wsf.stack.cxf.transport.ServletHelper.callRequestHandler(ServletHelper.java:156) [jbossws-cxf-server.jar:4.1.1.Final]
      
      
      
      at org.jboss.wsf.stack.cxf.CXFServletExt.invoke(CXFServletExt.java:87) [jbossws-cxf-server.jar:4.1.1.Final]
      
      
      
      at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:225) [cxf-rt-transports-http.jar:2.6.4]
      
      
      
      at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:145) [cxf-rt-transports-http.jar:2.6.4]
      
      
      
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:754) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
      
      
      
      at org.jboss.wsf.stack.cxf.CXFServletExt.service(CXFServletExt.java:135) [jbossws-cxf-server.jar:4.1.1.Final]
      
      
      
      at org.jboss.wsf.spi.deployment.WSFServlet.service(WSFServlet.java:140) [jbossws-spi.jar:2.1.1.Final]
      
      
      
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
      
      
      
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
      
      
      
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
      
      
      
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
      
      
      
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
      
      
      
      at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
      
      
      
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
      
      
      
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
      
      
      
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
      
      
      
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
      
      
      
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
      
      
      
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
      
      
      
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
      
      
      
      at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_45]
      
      
      
      Caused by: java.lang.NullPointerException
      
      
      
      
      at br.com.gid.ws.interfaces.impl.TesteImpl.adicionarPerfilOiVende(TesteImpl.java:63) [classes:]
      
      
      
      ... 41 more
      
      
      
      
      
      13:31:48,047 AVISO [org.apache.cxf.phase.PhaseInterceptorChain] (http-localhost-127.0.0.1-8080-1) Application {http://gid.ws.nds.teste/}Teste#{http://gid.ws.nds.OiVende/}adicionarPerfilOiVende has thrown exception, unwinding now: org.apache.cxf.interceptor.Fault
      
      
      
      
      at org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:162) [cxf-api.jar:2.6.4]
      
      
      
      at org.apache.cxf.jaxws.AbstractJAXWSMethodInvoker.createFault(AbstractJAXWSMethodInvoker.java:213) [cxf-rt-frontend-jaxws.jar:2.6.4]
      
      
      
      at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:128) [cxf-api.jar:2.6.4]
      
      
      
      at org.apache.cxf.jaxws.AbstractJAXWSMethodInvoker.invoke(AbstractJAXWSMethodInvoker.java:178) [cxf-rt-frontend-jaxws.jar:2.6.4]
      
      
      
      at org.apache.cxf.jaxws.JAXWSMethodInvoker.invoke(JAXWSMethodInvoker.java:64) [cxf-rt-frontend-jaxws.jar:2.6.4]
      
      
      
      at org.jboss.wsf.stack.cxf.JBossWSInvoker.invoke(JBossWSInvoker.java:129) [jbossws-cxf-server.jar:4.1.1.Final]
      
      
      
      at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58) [cxf-api.jar:2.6.4]
      
      
      
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439) [rt.jar:1.6.0_45]
      
      
      
      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) [rt.jar:1.6.0_45]
      
      
      
      at java.util.concurrent.FutureTask.run(FutureTask.java:138) [rt.jar:1.6.0_45]
      
      
      
      at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37) [cxf-api.jar:2.6.4]
      
      
      
      at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:107) [cxf-api.jar:2.6.4]
      
      
      
      at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262) [cxf-api.jar:2.6.4]
      
      
      
      at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) [cxf-api.jar:2.6.4]
      
      
      
      at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:236) [cxf-rt-transports-http.jar:2.6.4]
      
      
      
      at org.jboss.wsf.stack.cxf.RequestHandlerImpl.handleHttpRequest(RequestHandlerImpl.java:95) [jbossws-cxf-server.jar:4.1.1.Final]
      
      
      
      at org.jboss.wsf.stack.cxf.transport.ServletHelper.callRequestHandler(ServletHelper.java:156) [jbossws-cxf-server.jar:4.1.1.Final]
      
      
      
      at org.jboss.wsf.stack.cxf.CXFServletExt.invoke(CXFServletExt.java:87) [jbossws-cxf-server.jar:4.1.1.Final]
      
      
      
      at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:225) [cxf-rt-transports-http.jar:2.6.4]
      
      
      
      at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:145) [cxf-rt-transports-http.jar:2.6.4]
      
      
      
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:754) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
      
      
      
      at org.jboss.wsf.stack.cxf.CXFServletExt.service(CXFServletExt.java:135) [jbossws-cxf-server.jar:4.1.1.Final]
      
      
      
      at org.jboss.wsf.spi.deployment.WSFServlet.service(WSFServlet.java:140) [jbossws-spi.jar:2.1.1.Final]
      
      
      
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
      
      
      
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
      
      
      
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
      
      
      
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
      
      
      
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
      
      
      
      at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
      
      
      
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
      
      
      
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
      
      
      
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
      
      
      
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
      
      
      
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
      
      
      
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
      
      
      
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
      
      
      
      at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_45]
      
      
      
      Caused by: java.lang.NullPointerException
      
      
      
      
      at br.com.gid.ws.interfaces.impl.TesteImpl.adicionarPerfilOiVende(TesteImpl.java:63) [classes:]
      
      
      
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.6.0_45]
      
      
      
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [rt.jar:1.6.0_45]
      
      
      
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [rt.jar:1.6.0_45]
      
      
      
      at java.lang.reflect.Method.invoke(Method.java:597) [rt.jar:1.6.0_45]
      
      
      
      at org.jboss.ws.common.invocation.AbstractInvocationHandlerJSE.invoke(AbstractInvocationHandlerJSE.java:108) [jbossws-common.jar:2.1.1.Final]
      
      
      
      at org.jboss.wsf.stack.cxf.JBossWSInvoker.performInvocation(JBossWSInvoker.java:149) [jbossws-cxf-server.jar:4.1.1.Final]
      
      
      
      at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96) [cxf-api.jar:2.6.4]
      
      
      
      

       

      jbossws-cxf.xml

      <beans xmlns="http://www.springframework.org/schema/beans"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:jaxws="http://cxf.apache.org/jaxws"
             xmlns:cxf="http://cxf.apache.org/core"
             xmlns:soap="http://cxf.apache.org/bindings/soap"
             xmlns:wsa="http://cxf.apache.org/ws/addressing"
             xmlns:http="http://cxf.apache.org/transports/http/configuration"
             xmlns:wsrm-policy="http://schemas.xmlsoap.org/ws/2005/02/rm/policy"
             xmlns:wsrm-mgr="http://cxf.apache.org/ws/rm/manager"
             xmlns:jee="http://www.springframework.org/schema/jee"
          xmlns:tx="http://www.springframework.org/schema/tx"
             xmlns:context="http://www.springframework.org/schema/context"
          xmlns:aop="http://www.springframework.org/schema/aop"
             xsi:schemaLocation="
             http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
          http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
             http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
             http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
             http://schemas.xmlsoap.org/ws/2005/02/rm/policy http://schemas.xmlsoap.org/ws/2005/02/rm/wsrm-policy.xsd
             http://cxf.apache.org/ws/rm/manager http://cxf.apache.org/schemas/configuration/wsrm-manager.xsd      
             http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
      
        <context:component-scan base-package="br.com.gid.ws.*" />
      
        <jaxws:endpoint id='Teste' 
        address='http://localhost:8080/Teste'
          implementor='br.com.gid.ws.interfaces.impl.TesteImpl'>
        </jaxws:endpoint>
      
      
      </beans>
      

       

      web.xml

      <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>br.com.gid.ws</groupId>
        <artifactId>Teste</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>war</packaging>
        <name>br.com.gid.ws</name>
      
      
        <properties>
      
      
        <project.build.sourceEncoding>ISO-8859-1</project.build.sourceEncoding>
        <org.springframework.version>3.0.7.RELEASE</org.springframework.version>
      
      
      
      
        </properties>
      
        <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${org.springframework.version}</version>
        </dependency>
      
      
        <dependency>
        <groupId>org.springframework.ldap</groupId>
        <artifactId>spring-ldap-core</artifactId>
        <version>1.3.2.RELEASE</version>
        </dependency>
      
      
        <!-- CXF -->
      
        <dependency>
        <groupId>org.jboss.ws.cxf</groupId>
        <artifactId>jbossws-cxf-client</artifactId>
        <version>4.2.3.Final</version>
        </dependency>
                  
        </dependencies>
      
      
        <build>
        <finalName>Teste</finalName>
        </build>
      
      
      </project>
      

       

      Thanks in advance.