How to use WSDL with spring-boot?

前端 未结 5 2066
臣服心动
臣服心动 2020-12-25 14:48

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, th

5条回答
  •  别那么骄傲
    2020-12-25 15:32

    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.

提交回复
热议问题