1

I have web.xml and applicationContext.xml from Spring's project. I want to change this and get only Java configuration for my project but I can't figure how.

web-xml

<web-app id="WebApp_ID" version="2.4"
  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/j2ee
  http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

  <display-name>Spring + JAX-WS</display-name>

  <servlet>
    <servlet-name>jaxws-servlet</servlet-name>
      <servlet-class>
        com.sun.xml.ws.transport.http.servlet.WSSpringServlet
      </servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>jaxws-servlet</servlet-name>
    <url-pattern>/hello</url-pattern>
  </servlet-mapping>

  <!-- Register Spring Listener -->
  <listener>
    <listener-class>
      org.springframework.web.context.ContextLoaderListener
    </listener-class>
  </listener>

</web-app>

applicationContext.xml

<?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:ws="http://jax-ws.dev.java.net/spring/core"
       xmlns:wss="http://jax-ws.dev.java.net/spring/servlet"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://jax-ws.dev.java.net/spring/core
        http://jax-ws.dev.java.net/spring/core.xsd
        http://jax-ws.dev.java.net/spring/servlet
        http://jax-ws.dev.java.net/spring/servlet.xsd"
>

    <wss:binding url="/hello">
        <wss:service>
            <ws:service bean="#helloWs"/>
        </wss:service>
    </wss:binding>

    <!-- Web service methods -->
    <bean id="helloWs" class="it.capgemini.HelloWorldWS">
      <property name="helloWorldBo" ref="HelloWorldBo" />
    </bean>

    <bean id="HelloWorldBo" class="it.capgemini.soap.HelloWorlBoImpl" />

</beans>

Thanks for any suggestion!

2

1 Answer 1

3

Spring provides a convenient base class for JAX-WS servlet endpoint implementations - SpringBeanAutowiringSupport. To expose our HelloService we extend Spring’s SpringBeanAutowiringSupport class and implement our business logic here, usually delegating the call to the business layer. We’ll simply use Spring’s @Autowired annotation for expressing such dependencies on Spring-managed beans.

@WebService(serviceName="hello")
public class HelloServiceEndpoint extends SpringBeanAutowiringSupport {
    @Autowired
    private HelloService service;

    @WebMethod
    public void helloWs() {
        service.hello();
    }
}

The service itself:

public class HelloService {
    public void hello() {
        // impl
    }
}

And configuration

@Configuration
public class JaxWsConfig {

    @Bean
    public ServletRegistrationBean wsSpringServlet() {
        return new ServletRegistrationBean(new WSSpringServlet(),    "/api/v10");
    }

    @Bean
    public HelloService helloService() {
        return new HelloService();
    }
}
Sign up to request clarification or add additional context in comments.

7 Comments

Thanks for comment. So I can use this two classes instead of xml configuration file?
Yes, also you need add Configuration to your app.
I can't find WSSpringServlet(), I'm on SpringBoot 1.3.3
Add following mvnrepository.com/artifact/com.sun.xml.ws/jaxws-rt/2.2.10 depemdency to your project.
@MikeShauneu what if I can't use WSSpringServlet?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.