Springws 简明教程
Spring WS - Static WSDL
在上一章 Spring -WS - First Application 中,我们已使用 Spring WS 配置自动生成了 WSDL。本例中,我们将演示如何使用 Spring WS 公开现有的 WSDL。
Step |
Description |
1 |
在包 com.tutorialspoint 中创建一个名为 leaveService 的项目,如 Spring WS - 第一个应用程序章节中所述。 |
2 |
在 /WEB-INF/wsdl 子文件夹下创建一个 WSDL leave.wsdl。 |
3 |
更新 /WEB-INF 子文件夹下的 spring-ws-servlet.xml。这里我们使用的是 static-wsdl 而不是 static-wsdl。 |
4 |
最后一步是创建所有源和配置文件的内容,并导出应用程序,如以下所述。 |
/WEB-INF/spring-ws-servlet.xml
<wsdl:definitions xmlns:wsdl = "http://schemas.xmlsoap.org/wsdl/"
xmlns:soap = "http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:schema = "http://tutorialspoint.com/hr/schemas"
xmlns:tns = "http://tutorialspoint.com/hr/definitions"
targetNamespace = "http://tutorialspoint.com/hr/definitions">
<wsdl:types>
<xsd:schema xmlns:xsd = "http://www.w3.org/2001/XMLSchema">
<xsd:import namespace = "http://tutorialspoint.com/hr/schemas"
schemaLocation = "hr.xsd"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name = "LeaveRequest">
<wsdl:part element = "schema:LeaveRequest" name = "LeaveRequest"/>
</wsdl:message>
<wsdl:portType name = "HumanResource">
<wsdl:operation name = "Leave">
<wsdl:input message = "tns:LeaveRequest" name = "LeaveRequest"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name = "HumanResourceBinding" type = "tns:HumanResource">
<soap:binding style = "document"
transport = "http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name = "Leave">
<soap:operation soapAction = "http://mycompany.com/RequestLeave"/>
<wsdl:input name = "LeaveRequest">
<soap:body use = "literal"/>
</wsdl:input>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name = "HumanResourceService">
<wsdl:port binding = "tns:HumanResourceBinding" name = "HumanResourcePort">
<soap:address location = "http://localhost:8080/leaveService/"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
/WEB-INF/spring-ws-servlet.xml
<beans xmlns = "http://www.springframework.org/schema/beans"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xmlns:context = "http://www.springframework.org/schema/context"
xmlns:sws = "http://www.springframework.org/schema/web-services"
xsi:schemaLocation = "http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/web-services
http://www.springframework.org/schema/web-services/web-services-2.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package = "com.tutorialspoint.hr"/>
<sws:annotation-driven/>
<sws:static-wsdl id = "leave" location = "/WEB-INF/wsdl/leave.wsdl"/>
</beans>
Run the Project
创建完源和配置文件后,我们应该导出应用程序。在应用程序上单击右键,使用导出 → WAR 文件选项,然后在 Tomcat 的 webapps 文件夹中保存 leaveService.war 文件。
现在,启动 Tomcat 服务器,并确保我们可以使用标准浏览器访问 webapps 文件夹中的其他网页。尝试访问 URL – [role="bare"] [role="bare"]http://localhost:8080/leaveService/leave.wsdl ,如果 Spring Web 应用程序一切正常,我们会看到以下屏幕。