我有客户端提供的 WSDL 和架构文件。我需要使用此 WSDL 文件创建 Spring-boot SOAP Web 服务。我在 google 上搜索了所有我能找到的示例,它们使用 spring 自动生成了 wsdl。我如何使用 WSDL 来生成 SOAP 服务?
最佳答案
以下是将现有 wsdl 与 Spring-Ws 和 Spring-boot 结合使用时需要遵循的常见步骤。
配置类
@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;
}
}
- 在您的 pom.xml 中使用“jaxb2-maven-plugin”插件从您的 wsdl 生成类。
- 在Spring-WS中,你必须自己编写端点。没有端点的代码生成。写起来很容易。您可以按照 Spring 网站上的教程/指南进行操作。
关于soap - 如何将 WSDL 与 spring-boot 结合使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33773346/