spring 使用DefaultWsdl11定义自动生成wsdl

lb3vh1jj  于 2023-01-25  发布在  Spring
关注(0)|答案(3)|浏览(139)

使用DefaultWsdl11Definition自动生成wsdl时遇到问题
ContactServiceOperations.xsd

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://com/blog/samples/webservices/contactservice"
xmlns:Contact="http://webservices.samples.blog.com" targetNamespace="http://com/blog/samples/webservices/Contact"
elementFormDefault="qualified">
<xsd:import namespace="http://webservices.samples.blog.com"
    schemaLocation="Contact.xsd" />
<xsd:element name="ContactRequest">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element name="Id" type="xsd:integer" />
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>
<xsd:element name="ContactResponse">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element name="Contact" type="Contact:Contact" />
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>

springapp-servlet.xml

<mvc:annotation-driven />

<sws:annotation-driven />

<context:component-scan base-package="*" />

<bean id="ContactService"
    class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition">
    <property name="schemaCollection">
        <bean
            class="org.springframework.xml.xsd.commons.CommonsXsdSchemaCollection">
            <property name="inline" value="true" />
            <property name="xsds">
                <list>
                    <value>/xsd/ContactServiceOperations.xsd</value>
                </list>
            </property>
        </bean>
    </property>
    <property name="portTypeName" value="ContactService" />
    <property name="locationUri" value="http://localhost:8080/SpringWS/ContactService/" />
</bean>

web.xml

<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<servlet>
    <servlet-name>springapp</servlet-name>
    <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>springapp</servlet-name>
    <url-pattern>/jsp/*</url-pattern>
</servlet-mapping>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:*.xml</param-value>
</context-param>

<listener>
    <listener-class>
           org.springframework.web.context.ContextLoaderListener
     </listener-class>
</listener>

<servlet>  
       <servlet-name>webservices</servlet-name>  
       <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>  
       <init-param>  
            <param-name>transformWsdlLocations</param-name>  
            <param-value>true</param-value>  
       </init-param>  
       <init-param>  
            <param-name>contextConfigLocation</param-name>  
            <param-value></param-value>  
       </init-param>  
  </servlet>
  <servlet-mapping>
       <servlet-name>webservices</servlet-name>
       <url-pattern>*.wsdl</url-pattern>
  </servlet-mapping>  
  <servlet-mapping>  
       <servlet-name>webservices</servlet-name>  
       <url-pattern>/ContactService/*</url-pattern>  
  </servlet-mapping>

我可以毫无错误地启动Tomcat。然后,我访问以下URL:http://localhost:8080/SpringWS/ContactService/contactService.wsdl和浏览器显示一个空白页面,而不是生成的wsdl。
可能我的配置有问题,有什么办法可以帮助我吗?
谢谢

mctunoxg

mctunoxg1#

已更正此问题,请联系服务.wsdl

localhost:8080/SpringWS/ContactService/ContactService.wsdl
8dtrkrch

8dtrkrch2#

web.xml文件有问题。请尝试为DispatcherServlet和MessageDispatcherServlet使用不同的上下文文件。

<servlet>
   <servlet-name>dispatcherServlet</servlet-name>
   <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
   <init-param>
       <param-name>contextConfigLocation</param-name>
       <param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
 </servlet>

.....
....

<servlet>  
   <servlet-name>webservices</servlet-name>  
   <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>  
   <init-param>  
       <param-name>transformWsdlLocations</param-name>  
       <param-value>true</param-value>  
    </init-param>  
    <init-param>  
        <param-name>contextConfigLocation</param-name>  
        <param-value>/WEB-INF/springws-config.xml</param-value>  
    </init-param>  
    <load-on-startup>1</load-on-startup>  
 </servlet>
hec6srdp

hec6srdp3#

我在运行Sping Boot 演示时也有过类似的经历。如果你的问题和我的问题一样,那么它就可以工作了。Spring发送带有xml头的wsdl。

<?xml version="1.0" encoding="UTF-8" standalone="no"?><wsdl:definitions ...

我用的是Firefox,它在显示黑屏之前会 Flink wsdl,所以查看页面的源代码时会显示完整的wsdl文件。
下面是一个使用Sping Boot 注解执行此操作的简单可下载示例:
https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-webservices

相关问题