【问题标题】:How to use spring web services dynamic WSDL generation in spring boot?如何在spring boot中使用spring web services动态WSDL生成?
【发布时间】:2019-02-27 23:59:19
【问题描述】:

我关注了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 提供 Web 服务自动配置,因此您只需定义 Endpoints。

使用 spring-boot-starter-webservices 模块可以轻松访问 Spring Web Services 功能。

SimpleWsdl11Definition 和 SimpleXsdSchema bean 可以分别为您的 WSDL 和 XSD 自动创建。为此,请配置它们的位置,如下例所示:

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

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

【问题讨论】:

标签: java spring web-services spring-boot


【解决方案1】:

通过查看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–annotated 类旁边,因此无需进一步配置即可发现它——设置的值与 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 架构文件,可以使用以下内容生成相应的 WSDL 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;
    }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-11
    • 2015-07-23
    • 2018-11-22
    • 1970-01-01
    • 2017-02-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多