Listing 17-10. The DispatcherServlet Configuration
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
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">
<annotation-driven />
<resources mapping="/resources/**" location="/resources/" />
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jspx" />
</beans:bean>
<context:component-scan
base-package="com.apress.prospring3.ch17.web.controller" />
</beans:beans>
As shown in Listing 17-10, the mvc namespace is declared as the default namespace. The
<annotation-driven> tag enables the support of annotation configuration for Spring MVC controllers, as
well as enabling Spring 3 type conversion and formatting support. Also, support for JSR-303 Bean
Validation is enabled by this tag. The <resources> tag defines the static resources (for example, CSS,
JavaScript, images, and so on) and their locations so Spring MVC can improve the performance in
serving those files. The <context:component-scan> tag should be familiar to you.
For the ViewResolver interface, we will keep on using the InternalResourceViewResolver class as the
implementation. However, for the suffix, we will change it to .jspx.
Implement the ContactController
Having the DispatherServlet's WebApplicationContext configured, the next step is to implement the
controller class. Listing 17-11 shows the ContactController class.
Listing 17-11. The ContactController Class
package com.apress.prospring3.ch17.web.controller;
import java.util.List;
import
org.slf4j.Logger;
import
org.slf4j.LoggerFactory;
import
org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Controller;
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home