How to use WSDL with spring-boot?

前端 未结 5 2067
臣服心动
臣服心动 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:18

    You can create WebServiceConfiguration java class in your packages.

    @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, "/ProjectName/*");
        }
        @Bean(name = "wsdlname")
        public DefaultWsdl11Definition defaultWsdl11Definition (XsdSchema cityRequestSchema) {
            DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
            wsdl11Definition.setRequestSuffix("ByCountry");
            wsdl11Definition.setResponseSuffix("City");
            wsdl11Definition.setPortTypeName("Hotelport");
            wsdl11Definition.setLocationUri("/ProjectName");
            wsdl11Definition.setTargetNamespace("http://spring.io/guides/gs-producing-web-service");
            wsdl11Definition.setSchema(cityRequestSchema);
            return wsdl11Definition;
    
        }
    
        @Bean
    public XsdSchema cityRequestSchema() {
        return new SimpleXsdSchema(new ClassPathResource("CityRequest.xsd"));
    }
    

    After run as spring boot app...then copy paste this url in your browser. http://localhost:8080/ProjectName/wsdlname.wsdl

    noted:localhost:8080 to replace with your tomcat port

提交回复
热议问题