Java Reference
In-Depth Information
How It Works
Setting Up a Spring-WS Application
To implement a web service using Spring-WS, you first create the following directory structure for your
web application context. Ensure that your
lib
directory contains the latest version of Spring-WS.
weather/
WEB-INF/
classes/
lib/*jar
temperature.xsd
weather-servlet.xml
web.xml
In
web.xml
, you have to configure the
MessageDispatcherServlet
servlet of Spring-WS, which is
different from
DispatcherServlet
for a typical Spring MVC application. This servlet specializes in
dispatching web service messages to appropriate endpoints and detecting the framework facilities
of Spring-WS.
<web-app version="2.4" xmlns="
http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/j2ee
<servlet>
<servlet-name>weather</servlet-name>
<servlet-class>
org.springframework.ws.transport.http.MessageDispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>weather</servlet-name>
<url-pattern>
/services/*</url-pattern>
</servlet-mapping>
</web-app>
In the Spring MVC configuration file,
weather-servlet.xml
, you first declare a bean for the weather
service implementation. Later, you will define endpoints and mappings to handle the web service
requests.
<beans xmlns="
http://www.springframework.org/schema/beans"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
<bean id="weatherService"
class="com.apress.springenterpriserecipes.weather.WeatherServiceImpl" />
</beans>
Search WWH ::
Custom Search