Web Services
Spring Boot 提供了 Web 服务自动配置,因此你必须做的是定义你的 Endpoints
。
Spring Boot provides Web Services auto-configuration so that all you must do is define your Endpoints
.
可以通过 spring-boot-starter-webservices
模块轻松访问 {url-spring-webservices-docs}[Spring Web 服务功能]。
The {url-spring-webservices-docs}[Spring Web Services features] can be easily accessed with the spring-boot-starter-webservices
module.
SimpleWsdl11Definition
和 SimpleXsdSchema
bean 可以分别自动为你的 WSDL 和 XSD 创建。要做到这一点,请配置它们的位置,如下例所示:
SimpleWsdl11Definition
and SimpleXsdSchema
beans can be automatically created for your WSDLs and XSDs respectively.
To do so, configure their location, as shown in the following example:
spring: webservices: wsdl-locations: "classpath:/wsdl"
Calling Web Services with WebServiceTemplate
如果你需要从应用程序中调用远程 Web 服务,可以使用 {url-spring-webservices-docs}#client-web-service-template[WebServiceTemplate
] 类。由于 WebServiceTemplate
实例经常需要在使用前进行自定义,因此 Spring Boot 不会提供任何单一的自动配置 WebServiceTemplate
bean。但它会自动配置一个 WebServiceTemplateBuilder
,可在需要时用于创建 WebServiceTemplate
实例。
If you need to call remote Web services from your application, you can use the {url-spring-webservices-docs}#client-web-service-template[WebServiceTemplate
] class.
Since WebServiceTemplate
instances often need to be customized before being used, Spring Boot does not provide any single auto-configured WebServiceTemplate
bean.
It does, however, auto-configure a WebServiceTemplateBuilder
, which can be used to create WebServiceTemplate
instances when needed.
以下代码显示了一个典型的示例:
The following code shows a typical example:
默认情况下,WebServiceTemplateBuilder
会使用类路径中可用的 HTTP 客户端库 检测到一个合适的基于 HTTP 的 WebServiceMessageSender
。还可以按以下方式自定义读取和连接超时:
By default, WebServiceTemplateBuilder
detects a suitable HTTP-based WebServiceMessageSender
using the available HTTP client libraries on the classpath.
You can also customize read and connection timeouts as follows: