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)
有许多选项可以从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服务.
| 归档时间: |
|
| 查看次数: |
39493 次 |
| 最近记录: |