如何在spring-boot中使用WSDL?

use*_*599 15 soap spring-ws spring-boot

我有客户端提供的WSDL和模式文件.我需要使用此WSDL文件创建Spring-boot SOAP Web服务.我有谷歌它和我能找到的所有例子,他们用spring自动生成wsdl.我如何使用我的WSDL生成SOAP服务?

Ket*_*tan 19

以下是使用现有的带有Spring-Ws和Spring-boot的wsdl的常用步骤.

配置类

@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;
    }
}
Run Code Online (Sandbox Code Playgroud)
  1. 在你的pom.xml中使用'jaxb2-maven-plugin'插件从你的wsdl生成类.
  2. 在Spring-WS中,您必须自己编写端点.没有为端点生成代码.它易于编写.你可以按照春季网站上的教程/指南.

  • 很好,这很有用!我看到预期的网址是"http:// localhost:8080/ws/services.wsdl".如果必须有一个explisit url,如http:// localhost:8080/ws/services/basic?wsdl,该怎么办? (2认同)

Cod*_*und 8

有许多选项可以从WSDL文件开始并使用Spring Boot公开Web服务.您通常会从WSDL定义生成Java类.有许多JAXB Maven插件可以帮助您完成此操作.

此外,在使用Spring Boot时,请确保利用spring-boot-starters来自动管理不同的所需依赖项.

一种方法是将Spring Web Services与maven-jaxb2-plugin插件结合使用.我已经创建了一个循序渐进的教程,该教程解释了如何使用Spring-WS从消费者和提供者的WSDL文件开始.

另一种方法是将Apache CXF等框架与cxf-codegen-plugin插件结合使用.CXF还附带了它自己的CXF春季启动首发cxf-spring-boot-starter-jaxws.为了让您入门,我编译了一个示例,示例将CXF启动器与Spring Boot结合使用,从WSDL文件开始创建Web服务.