Jboss 7.1: Spring based CXF WebService bean injection failed.
hhiep Jul 31, 2012 5:56 AMHi,
My webservice (using cxf 2.4.6, spring 3.0.6) can deploy and run OK on Jboss 7.0.2 Final. But on JBoss 7.1 (I test with 7.1.1 Final, and 7.1.0 Beta1b) this service can deployed with no error, but when client call method of service there is nullPointerException, caused by subservice that is a bean injected to the webservice is null at runtime.
I based on this link http://middlewaremagic.com/jboss/?p=1106 to create my test service.
Is there anything changed about bean injection on Jboss 7.1?
Thank you,
Hiep
This is my configs file and error log:
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/appContext.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <servlet> <servlet-name>CXFServlet</servlet-name> <servlet-class> org.apache.cxf.transport.servlet.CXFServlet </servlet-class> </servlet> <servlet-mapping> <servlet-name>CXFServlet</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> </web-app>
appContext.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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <!-- <import resource="classpath:META-INF/cxf/cxf.xml" /> <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> --> <bean id="subServiceBean" class="SubServiceImpl"></bean> <bean id="springCxfServiceBean" class="Spring_CXF_Service"> <property name="subService" ref="subServiceBean"/> </bean> <jaxws:endpoint id="cxfSpringServiceHelloWorld" implementor="#springCxfServiceBean" address="/Spring_CXF_Service" /> </beans>
Implement service:
Interface Spring_CXF_Service_Intf .java
import javax.jws.WebService; @WebService public interface Spring_CXF_Service_Intf { public String sayHello(String name); public String sayHi(String name); }
implementation:
import javax.jws.WebService; @WebService(endpointInterface = "Spring_CXF_Service_Intf") public class Spring_CXF_Service implements Spring_CXF_Service_Intf { private SubService subService; public void setSubService(SubService subService) { this.subService = subService; } public String sayHello(String name) { System.out.println("[Spring_CXF_Service] sayHello(" + name + ") invoked."); return "Hello World !!! Mr. " + name; } public String sayHi(String name) { return subService.sayHi(name); } }
SubService.java
public interface SubService { public String sayHi(String name); }
SubServiceImpl .java
public class SubServiceImpl implements SubService { public String sayHi(String name) { return "Hi all!"; } }
====== Exception:
18:43:06,352 INFO [org.apache.cxf.service.factory.ReflectionServiceFactoryBean] (MSC service thread 1-6) Creating Service {http://unknown.namespace/}Spring_ CXF_ServiceService from class Spring_CXF_Service_Intf 18:43:06,614 INFO [org.apache.cxf.endpoint.ServerImpl] (MSC service thread 1-6) Setting the server's publish address to be /Spring_CXF_Service 18:43:06,624 INFO [org.springframework.web.context.ContextLoader] (MSC service thread 1-6) Root WebApplicationContext: initialization completed in 734 ms 18:43:06,702 INFO [org.jboss.web] (MSC service thread 1-6) registering web context: /bean 18:43:06,752 INFO [org.jboss.as.server.controller] (DeploymentScanner-threads - 2) Deployed "bean.war" 18:43:20,864 INFO [stdout] (http-user-PC-192.168.1.102-8080-1) [Spring_CXF_Service] sayHello(Middleware Magic) invoked. 18:43:20,988 ERROR [org.jboss.ws.common.invocation.InvocationHandlerJAXWS] (http-user-PC-192.168.1.102-8080-1) Method invocation failed with exception: null: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_30] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_30] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_30] at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_30] at org.jboss.ws.common.invocation.AbstractInvocationHandlerJSE.invoke(AbstractInvocationHandlerJSE.java:111) at org.jboss.wsf.stack.cxf.JBossWSInvoker._invokeInternal(JBossWSInvoker.java:169) at org.jboss.wsf.stack.cxf.JBossWSInvoker.invoke(JBossWSInvoker.java:117) at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58) [cxf-rt-core-2.4.6.jar:] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) [:1.6.0_30] at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) [:1.6.0_30] at java.util.concurrent.FutureTask.run(FutureTask.java:138) [:1.6.0_30] at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37) [cxf-rt-core-2.4.6.jar:] at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:106) [cxf-rt-core-2.4.6.jar:] at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263) [cxf-api-2.4.6.jar:] at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) [cxf-rt-core-2.4.6.jar:] at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:206) [cxf-rt-transports-http-2.4.6.jar:] at org.jboss.wsf.stack.cxf.RequestHandlerImpl.handleHttpRequest(RequestHandlerImpl.java:91) at org.jboss.wsf.stack.cxf.transport.ServletHelper.callRequestHandler(ServletHelper.java:174) at org.jboss.wsf.stack.cxf.CXFServletExt.invoke(CXFServletExt.java:87) at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:184) [cxf-rt-transports-http-2.4.6.jar:] at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:107) [cxf-rt-transports-http-2.4.6.jar:] at javax.servlet.http.HttpServlet.service(HttpServlet.java:754) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:] at org.jboss.wsf.stack.cxf.CXFServletExt.service(CXFServletExt.java:135) at org.jboss.wsf.spi.deployment.WSFServlet.service(WSFServlet.java:140) [jbossws-spi-2.0.0.CR1.jar:] at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.3.Final.jar:] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.3.Final.jar:] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.3.Final.jar:] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.3.Final.jar:] at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285) at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261) at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:151) [jboss-as-web-7.1.0.Beta1b.jar:] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.3.Final.jar:] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.3.Final.jar:] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.3.Final.jar:] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [jbossweb-7.0.3.Final.jar:] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.3.Final.jar:] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.3.Final.jar:] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.3.Final.jar:] at java.lang.Thread.run(Thread.java:662) [:1.6.0_30] Caused by: java.lang.NullPointerException at Spring_CXF_Service.sayHi(Spring_CXF_Service.java:20) ... 40 more 18:43:20,999 WARNING [org.apache.cxf.phase.PhaseInterceptorChain] (http-user-PC-192.168.1.102-8080-1) Application {http:///}Spring_CXF_ServiceService#{http:/ /unknown.namespace/}sayHi has thrown exception, unwinding now: org.apache.cxf.interceptor.Fault at org.jboss.wsf.stack.cxf.JBossWSInvoker.createFault(JBossWSInvoker.java:234) at org.jboss.wsf.stack.cxf.JBossWSInvoker._invokeInternal(JBossWSInvoker.java:189) at org.jboss.wsf.stack.cxf.JBossWSInvoker.invoke(JBossWSInvoker.java:117) at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58) [cxf-rt-core-2.4.6.jar:] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) [:1.6.0_30] at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) [:1.6.0_30] at java.util.concurrent.FutureTask.run(FutureTask.java:138) [:1.6.0_30] at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37) [cxf-rt-core-2.4.6.jar:] at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:106) [cxf-rt-core-2.4.6.jar:] at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263) [cxf-api-2.4.6.jar:] at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) [cxf-rt-core-2.4.6.jar:] at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:206) [cxf-rt-transports-http-2.4.6.jar:] at org.jboss.wsf.stack.cxf.RequestHandlerImpl.handleHttpRequest(RequestHandlerImpl.java:91) at org.jboss.wsf.stack.cxf.transport.ServletHelper.callRequestHandler(ServletHelper.java:174) at org.jboss.wsf.stack.cxf.CXFServletExt.invoke(CXFServletExt.java:87) at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:184) [cxf-rt-transports-http-2.4.6.jar:] at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:107) [cxf-rt-transports-http-2.4.6.jar:] at javax.servlet.http.HttpServlet.service(HttpServlet.java:754) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:] at org.jboss.wsf.stack.cxf.CXFServletExt.service(CXFServletExt.java:135) at org.jboss.wsf.spi.deployment.WSFServlet.service(WSFServlet.java:140) [jbossws-spi-2.0.0.CR1.jar:] at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.3.Final.jar:] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.3.Final.jar:] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.3.Final.jar:] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.3.Final.jar:] at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285) at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261) at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:151) [jboss-as-web-7.1.0.Beta1b.jar:] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.3.Final.jar:] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.3.Final.jar:] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.3.Final.jar:] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [jbossweb-7.0.3.Final.jar:] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.3.Final.jar:] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.3.Final.jar:] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.3.Final.jar:] at java.lang.Thread.run(Thread.java:662) [:1.6.0_30] Caused by: java.lang.NullPointerException at Spring_CXF_Service.sayHi(Spring_CXF_Service.java:20) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_30] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_30] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_30] at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_30] at org.jboss.ws.common.invocation.AbstractInvocationHandlerJSE.invoke(AbstractInvocationHandlerJSE.java:111) at org.jboss.wsf.stack.cxf.JBossWSInvoker._invokeInternal(JBossWSInvoker.java:169) ... 34 more