Spring Web Services Tutorial on Spring WS Static WSDL

in the previous chapter spring -ws - first application, we have generated wsdl automatically using the spring ws configuration. in this case, we will display how to expose the existing wsdl using the spring ws.

step description
1 create a project with a name leaveservice under a package com.tutorialspoint as explained in the spring ws - first application chapter.
2 create a wsdl leave.wsdl under the /web-inf/wsdl sub-folder.
3 update spring-ws-servlet.xml under the /web-inf sub-folder. we are using the static-wsdl tag here instead of the dynamic-wsdl.
4 the final step is to create content of all source and configuration files and export the application as explained below.

/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

once we are done with creating source and configuration files, we should export the application. right click on the application, use export → war file option and save your leaveservice.war file in tomcat's webapps folder.

now, start the tomcat server and ensure that we can access other webpages from the webapps folder using a standard browser. try to access the url – http://localhost:8080/leaveservice/leave.wsdl, if everything is ok with the spring web application, we will see the following screen.

static wsdl result