代码之家  ›  专栏  ›  技术社区  ›  watery

如何在springboot中使用springwebservices动态WSDL生成?

  •  2
  • watery  · 技术社区  · 6 年前

    我跟着 Spring Web Services Getting Started tutorial /ws/holiday.wsdl /ws/holidayService ,到目前为止还不错。

    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 ''
    

    documentation on Web Service 说:

    springboot提供了Web服务的自动配置,所以您所要做的就是定义端点。

    springwebservices特性可以通过springbootstarterwebservices模块轻松访问。

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

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

    1 回复  |  直到 4 年前
        1
  •  0
  •   watery    6 年前

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

    web.xml

    删除了 网站.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

    三。 hr.xsd

    架构文件到 src/main/resources/ws 并补充道

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

    应用程序属性


    更新

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

    holiday-spring-schema.xsd holiday-winter-schema.xsd holiday-spring.wsdl holiday-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;
        }
    
    }