【问题标题】:Spring WS Exposing XSD isn't workingSpring WS 暴露 XSD 不起作用
【发布时间】:2015-02-11 04:51:50
【问题描述】:

我已经按照这篇文章中的答案在我的应用程序中公开了 xsd - Is there a way to expose a static XSD in Spring WS 2?

我的 web.xml

<servlet>
        <servlet-name>ws</servlet-name>
        <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/springws-servlet.xml</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>ws</servlet-name>
        <url-pattern>/services</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>ws</servlet-name>
        <url-pattern>*.wsdl</url-pattern>
    </servlet-mapping>
    <servlet>
        <servlet-name>mvc</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/airlinemvc-servlet.xml</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>mvc</servlet-name>
        <url-pattern>*.do</url-pattern>

    </servlet-mapping>

springws-servlet.xml

    <sws:annotation-driven />


    <sws:static-wsdl id="airline" location="/WEB-INF/wsdl/airlineservice.wsdl"/>

    <sws:dynamic-wsdl id="airlineWS" 
                        portTypeName="AirlineServicePortType" 
                        locationUri="http://localhost:8080/airline/services/"
                        createSoap11Binding="true"
                        createSoap12Binding="true" >
        <sws:xsd location="/WEB-INF/schemas/AirlineService.xsd"/>

    </sws:dynamic-wsdl>

    <bean id="AirlineTypes" class="org.springframework.xml.xsd.SimpleXsdSchema">
        <property name="xsd" value="/WEB-INF/schemas/AirlineTypes.xsd"/>
    </bean>

   <bean id="AirlineService" class="org.springframework.xml.xsd.SimpleXsdSchema">
        <property name="xsd" value="/WEB-INF/schemas/AirlineService.xsd"/>
    </bean>

现在我想从浏览器访问 AirlineService.xsd。我尝试去http://localhost:8080/airline/AirlineService.xsdhttp://localhost:8080/airline/services/AirlineService.xsd - 他们都返回404。我犯了什么错误?提前致谢。

【问题讨论】:

  • 你不要把它们放在 WEB-INF 文件夹之外并通过localhost:8080/airline/schemas/AirlineService.xsd访问它们
  • @Koitoer 这很可能会起作用,但我的代码为什么不起作用真的很困扰我。我只是照原样复制了样本,但仍然没有运气。

标签: spring spring-mvc spring-ws


【解决方案1】:

我终于明白了。 MessageDispatcherServlet 无法处理对 .xsd 的请求,因为 web.xml 中没有 servlet-mapping 声明。

两种修复方法..

方法 1:更新 URL 模式以包含 /services/ 下的所有内容

    <servlet-mapping>
        <servlet-name>ws</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>

方法二:

添加另一个映射

    <servlet-mapping>
        <servlet-name>ws</servlet-name>
        <url-pattern>.xsd</url-pattern>
    </servlet-mapping>

【讨论】:

    【解决方案2】:

    发布于:

    http://www.mytechtip.com/2012/09/static-wsdl-with-imported-xml-schema-in.html

    你应该使用:

    `<bean 
        id="temperature-schema"
        class="org.springframework.xml.xsd.SimpleXsdSchema">
        <property 
            name="xsd" 
            value="/WEB-INF/wsdl/temperature-schema.xsd">
        </property>
    </bean>`
    

    其中 id 与包含您的架构的文件的名称匹配。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-14
      • 2019-02-01
      • 2021-03-13
      • 1970-01-01
      • 2020-04-03
      • 2018-06-19
      相关资源
      最近更新 更多