Spring – Using JAX-WS webservices with Spring 3.0.X on JBoss AS 7.1.X

autowiredjax-wsjboss7.xspring

I have some problems deploying a JAX-WS webservice with Spring 3.0.6 on JBoss AS Final 7.1.1.

I have tried two first method from this tutorial: http://www.javacodegeeks.com/2010/11/jaxws-with-spring-and-maven-tutorial.html

When I was using the first method (extending SpringBeanAutowiringSupport and declaring the servlet in web.xml) the application deploys correctly, but the beans that I inject in the webservice are Null.

Using the second method with SimpleJaxWsServiceExporter I am getting an error while deploying:

10:09:33,012 ERROR [org.springframework.web.context.ContextLoader] (MSC service thread 1-2) Context initialization failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter#0' defined in ServletContext resource [/WEB-INF/generic-applicationContext.xml]: Invocation of init method failed; nested exception is javax.xml.ws.WebServiceException: java.lang.RuntimeException: java.net.BindException: Address already in use: bind
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) [spring-context-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425) [spring-context-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:282) [spring-web-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:204) [spring-web-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47) [spring-web-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.13.Final.jar:]
    at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.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:886) [rt.jar:1.6.0_18]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_18]
    at java.lang.Thread.run(Thread.java:619) [rt.jar:1.6.0_18]
Caused by: javax.xml.ws.WebServiceException: java.lang.RuntimeException: java.net.BindException: Address already in use: bind
    at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:350)
    at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:239)
    at org.jboss.wsf.stack.cxf.client.ProviderImpl$DelegateEndpointImpl.publish(ProviderImpl.java:300)
    at org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter.publishEndpoint(SimpleJaxWsServiceExporter.java:68) [spring-web-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.remoting.jaxws.AbstractJaxWsServiceExporter.publishEndpoints(AbstractJaxWsServiceExporter.java:154) [spring-web-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.remoting.jaxws.AbstractJaxWsServiceExporter.afterPropertiesSet(AbstractJaxWsServiceExporter.java:125) [spring-web-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    ... 20 more

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" 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" version="2.5">

    <display-name>subscription-barring-service</display-name>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/generic-applicationContext.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
</web-app>

application context:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:task="http://www.springframework.org/schema/task"
    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/context http://www.springframework.org/schema/context/spring-context-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/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">

        <context:component-scan
            base-package="org.bluewin.bwsso.services.barring" />

        <bean class="org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter"/>
</beans>

webservice:

@Service("terminateSessionsEndpoint") 
@WebService(serviceName = "TerminateSessionsEndpoint", portName = "TerminateSessionsEndpoint")
public class TerminateSessionsEndpoint extends SpringBeanAutowiringSupport {

    private Logger logger = Logger.getLogger(TerminateSessionsEndpoint.class);

    @Autowired
    Service serviceImpl;

    @WebMethod(operationName = "TerminateAllSessionsForAccountId")
    @WebResult(name = "TerminateAllSessionsResponse") 
    public TerminateAllSessionsResponseVO terminateAllSessionsForAccountId(
            @WebParam(name = "TerminateAllSessionsRequest") 
            TerminateAllSessionsRequestVO requestWS) {

        //do some logic..
    }
}

Any clue how can I get it work?

Best Answer

I am also having problems deploying JAX-WS with similiar configuration. Indeed using the SpringBeanAutowiringSupport as described in Spring doc chapter "19.5.5 Exposing servlet-based web services using JAX-WS" doesn't work as expected.

See doc http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/remoting.html#remoting-web-services

But you are wrong here trying to use SimpleJaxWsServiceExporter. Chapter "19.5.6 Exporting standalone web services using JAX-WS" of spring doc.

This is making a conflict with web service that was was already registered by jboss.

For prove try following configuration with updated port number application context:

<bean class="org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter">
   <property name="baseAddress" value="http://localhost:8081/"/>
</bean>

In final you will run with two services exposed

http://localhost:8080/war-root/MyService?wsdl
http://localhost:8081/MyService?wsdl

As for now I found two workarounds proposed by other people:

  1. use org.springframework.beans.factory.config.AutowireCapableBeanFactory: Jax-ws, spring and SpringBeanAutowiringSupport
  2. move dependency injection to @PostConstruct method: JBoss 6 + Spring 3.0.5 + JAX-WS/CXF

Both workarounds are working fine.

Related Topic