<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/appServlet/restful-context.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>restful</servlet-name>
<url-pattern>/restful/*</url-pattern>
</servlet-mapping>
As shown in Listing 16-25, a servlet named restful is declared, which is of type DispatcherServlet
(details for the DispatcherServlet will be discussed in Chapters 17 and 18). In Spring MVC, each
DispatchServlet will have its own WebApplicationContext (however, all service-layer beans defined in
the root-context.xml file, which called the root WebApplicationContext, will be available for each
servlet's own WebApplicationContext too).
The <servlet-mapping> tag instructs the web container (for example, Tomcat) that all URLs under
the pattern /restful/* (for example, http://localhost:8080/ch16/restful/contact) will be handled by
the restful servlet.
As shown in Listing 16-25, for the restful servlet, we also specify that the Spring
WebApplicationContext for this DispatcherServlet should be loaded from /WEB-
INF/spring/appServlet/restful-context.xml. Listing 16-26 shows the configuration file.
Listing 16-26. The Spring WebApplicationContext for RESTful-WS
<?xml version="1.0" encoding="UTF-8"?>
<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:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
<mvc:annotation-driven>
<mvc:message-converters>
<bean
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>
<bean
class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
<property name="marshaller" ref="castorMarshaller"/>
<property name="unmarshaller" ref="castorMarshaller"/>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<context:component-scan
base-package="com.apress.prospring3.ch16.web.restful.controller"/>
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home