|
1 | 1 | package cn.iocoder.springboot.lab65.userservice.config;
|
2 | 2 |
|
3 |
| -import org.springframework.boot.autoconfigure.webservices.WebServicesProperties; |
| 3 | +import org.springframework.boot.web.servlet.ServletRegistrationBean; |
| 4 | +import org.springframework.context.ApplicationContext; |
4 | 5 | import org.springframework.context.annotation.Bean;
|
5 | 6 | import org.springframework.context.annotation.Configuration;
|
6 | 7 | import org.springframework.core.io.ClassPathResource;
|
| 8 | +import org.springframework.ws.config.annotation.EnableWs; |
| 9 | +import org.springframework.ws.transport.http.MessageDispatcherServlet; |
7 | 10 | import org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition;
|
8 | 11 | import org.springframework.xml.xsd.SimpleXsdSchema;
|
9 | 12 | import org.springframework.xml.xsd.XsdSchema;
|
10 | 13 |
|
11 | 14 | @Configuration
|
| 15 | +@EnableWs // 开启 Web Services 服务 |
12 | 16 | public class WebServiceConfig {
|
13 | 17 |
|
14 | 18 | public static final String NAMESPACE_URI = "https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-65/lab-65-spring-ws-demo";
|
15 | 19 |
|
| 20 | + @Bean |
| 21 | + public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) { |
| 22 | + MessageDispatcherServlet servlet = new MessageDispatcherServlet(); |
| 23 | + servlet.setApplicationContext(applicationContext); |
| 24 | + servlet.setTransformWsdlLocations(true); |
| 25 | + return new ServletRegistrationBean<>(servlet, "/ws/*"); |
| 26 | + } |
| 27 | + |
16 | 28 | @Bean
|
17 | 29 | public XsdSchema usersSchema() {
|
18 | 30 | return new SimpleXsdSchema(new ClassPathResource("users.xsd"));
|
19 | 31 | }
|
20 | 32 |
|
21 |
| - @Bean(name = "users") |
22 |
| - public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema usersSchema, WebServicesProperties properties) { |
23 |
| - DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition(); |
24 |
| - wsdl11Definition.setLocationUri(properties.getPath()); |
25 |
| - wsdl11Definition.setTargetNamespace(NAMESPACE_URI); |
26 |
| - wsdl11Definition.setSchema(usersSchema); |
| 33 | + @Bean(name = "users") |
| 34 | + public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema usersSchema) { |
| 35 | + DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition(); |
| 36 | + wsdl11Definition.setLocationUri("/ws"); |
| 37 | + wsdl11Definition.setTargetNamespace(NAMESPACE_URI); |
| 38 | + wsdl11Definition.setSchema(usersSchema); |
27 | 39 | wsdl11Definition.setPortTypeName("UsersPort");
|
28 | 40 | return wsdl11Definition;
|
29 |
| - } |
| 41 | + } |
30 | 42 |
|
31 | 43 | }
|
0 commit comments