How to use WSDL with spring-boot?

user3496599 picture user3496599 · Nov 18, 2015 · Viewed 52.6k times · Source

I have WSDL and schema files provided by client. I need to create Spring-boot SOAP web service with this WSDL file. I have google it and all the examples that I can find, they have auto-generate the wsdl with spring.How can I use my WSDL to generate the SOAP service?

Answer

Ketan picture Ketan · Dec 15, 2015

Here are the common steps to follow to use your existing wsdl with Spring-Ws and Spring-boot.

Config class

@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {
    @Bean
    public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(applicationContext);
        servlet.setTransformWsdlLocations(true);
        return new ServletRegistrationBean(servlet, "/ws/*");
    }

    //http://localhost:8080/ws/services.wsdl --bean name is set to 'services'
    @Bean(name = "services")
    public Wsdl11Definition defaultWsdl11Definition() {
        SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition();
        wsdl11Definition.setWsdl(new ClassPathResource("/schema/MyWsdl.wsdl")); //your wsdl location
        return wsdl11Definition;
    }
}
  1. In your pom.xml use 'jaxb2-maven-plugin' plugin to generate classes from your wsdl.
  2. In Spring-WS, you have to write endpoint yourself. No code generation for endpoints. Its easy to write. you can follow tutorial/guide on spring website.