java - 如何在 spring boot 中使用 spring web 服务动态 WSDL 生成?

标签 java spring web-services spring-boot

我关注了Spring Web Services Getting Started tutorial并且我已经将一个示例 Web 应用程序放在一起,该应用程序在 /ws/holiday.wsdl 动态生成 W​​SDL,端点在 /ws/holidayService 提供请求,到目前为止好。

现在我将该 Web 应用程序转换为 Spring Boot 应用程序:我添加了必要的 spring-boot-starter-* 依赖项,创建了一个 @SpringBootApplication 注释类在带有端点的包之上,端点实现仍然回复请求。

但我无法再从现有的 XSD 中获取生成的 WSDL。

这是 application.properties(我试过将 XSD 放在多个地方):

server.port = 8090
spring.webservices.wsdl-locations=classpath:/../;classpath:/wsdl
spring.webservices.path=/ws

这是 Run as -> Spring Boot App 日志(我在 Eclipse 中):

ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@13df2a8c: startup date [Mon Sep 24 14:40:44 CEST 2018]; root of context hierarchy
trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.ws.config.annotation.DelegatingWsConfiguration' of type [org.springframework.ws.config.annotation.DelegatingWsConfiguration$$EnhancerBySpringCGLIB$$22b02c9a] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
.w.s.a.s.AnnotationActionEndpointMapping : Supporting [WS-Addressing August 2004, WS-Addressing 1.0]
o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8090 (http)
o.apache.catalina.core.StandardService   : Starting service [Tomcat]
org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.34
o.a.catalina.core.AprLifecycleListener   : Loaded APR based Apache Tomcat Native library [1.2.16] using APR version [1.6.3].
o.a.catalina.core.AprLifecycleListener   : APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
o.a.catalina.core.AprLifecycleListener   : APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
o.a.catalina.core.AprLifecycleListener   : OpenSSL successfully initialized [OpenSSL 1.0.2m  2 Nov 2017]
o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2093 ms
o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
o.s.b.w.servlet.ServletRegistrationBean  : Servlet messageDispatcherServlet mapped to [/ws/*]
o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@13df2a8c: startup date [Mon Sep 24 14:40:44 CEST 2018]; root of context hierarchy
s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8090 (http) with context path ''

Spring Boot documentation on Web Service说:

Spring Boot provides Web Services auto-configuration so that all you must do is define your Endpoints.

The Spring Web Services features can be easily accessed with the spring-boot-starter-webservices module.

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

由于我是 Boot 的新手,我不清楚是否支持 WSDL 动态生成(我只是缺少正确的配置)或根本不支持。

最佳答案

通过查看 this guide ,我做了以下更改:

1。 web.xml

删除了 web.xml 文件以添加:

spring.webservices.servlet.init.transformWsdlLocations=true
spring.webservices.path=/ws

application.properties 文件。

2。 spring-ws-servlet.xml

删除了 spring-ws-servlet.xml 配置文件并添加:

@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {

    @Bean(name = "holiday")
    public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema schema) {
        DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
        wsdl11Definition.setPortTypeName("HumanResource");
        wsdl11Definition.setLocationUri("/holidayService/");
        wsdl11Definition.setTargetNamespace("http://mycompany.com/hr/definitions");
        wsdl11Definition.setSchema(schema);
        return wsdl11Definition;
    }

}

我把这个类放在了 @SpringBootApplication 旁边——注解类所以它不需要进一步配置就可以被发现——设置的值与 Spring servlet 配置文件中的值相同。

3。 hr.xsd

hr.xsd 模式文件移动到 src/main/resources/ws 并添加

spring.webservices.wsdl-locations=classpath:/ws/

application.properties 文件。


更新

也可以通过相应的不同模式输出多个单独的 WSDL 文件。

给定 holiday-spring-schema.xsdholiday-winter-schema.xsd 模式文件,相应的 WSDLs holiday-spring.wsdlholiday-winter.wsdl 可以通过以下方式生成:

@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {

    @Bean(name = "holiday-spring")
    public DefaultWsdl11Definition wsdl11DefinitionOne(@Qualifier("holiday-spring-schema") XsdSchema schema) {
        DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
        wsdl11Definition.setPortTypeName("HumanResource");
        wsdl11Definition.setLocationUri("/holidaySpringService/");
        wsdl11Definition.setTargetNamespace("http://mycompany.com/hr/definitions");
        wsdl11Definition.setSchema(schema);
        return wsdl11Definition;
    }

    @Bean(name = "holiday-winter")
    public DefaultWsdl11Definition wsdl11DefinitionTwo(@Qualifier("holiday-winter-schema") XsdSchema schema) {
        DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
        wsdl11Definition.setPortTypeName("HumanResource");
        wsdl11Definition.setLocationUri("/holidayWinterService/");
        wsdl11Definition.setTargetNamespace("http://mycompany.com/hr/definitions");
        wsdl11Definition.setSchema(schema);
        return wsdl11Definition;
    }

}

关于java - 如何在 spring boot 中使用 spring web 服务动态 WSDL 生成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52479912/

相关文章:

java - Spring RequestMapping 冲突

java - Http 响应内容类型为 json。 "Invalid mime type"错误

node.js - nginx 作为网络服务器,包括。 socket.io 和 node.js/ws ://400 Bad Request

ios - 如何防止 Core Data 在 iOS 5 中重复?

java.lang.NoSuchMethodError : javax. ws.rs.core.MultivaluedMap.addAll(Ljava/lang/Object;[Ljava/lang/Object;)V

java - 如何在桌面应用程序中实现 java 身份验证

java - 验证deleteObject是否确实删除了AWS S3 Java sdk中的对象

java - 如何打开 Android 设备的 GPS 设置?

java - 无法在 Windows 上的 Hadoop 中设置本地目录

java - 在 Spring Boot/执行器根端点上返回 404