From 97e189086746b5f200d9d735dedbd1df1cc6b879 Mon Sep 17 00:00:00 2001
From: Mic <misvy@vmware.com>
Date: Thu, 7 Feb 2013 10:01:53 +0800
Subject: [PATCH] web config enhancements

- web.xml is now simpler
- mvc config file has been split into 2 files
---
 .springBeans                                  | 14 ++++
 src/main/webapp/WEB-INF/mvc-core-config.xml   | 58 ++++++++++++++
 ...clinic-servlet.xml => mvc-view-config.xml} | 52 +------------
 src/main/webapp/WEB-INF/web.xml               | 78 +++----------------
 4 files changed, 87 insertions(+), 115 deletions(-)
 create mode 100644 .springBeans
 create mode 100644 src/main/webapp/WEB-INF/mvc-core-config.xml
 rename src/main/webapp/WEB-INF/{petclinic-servlet.xml => mvc-view-config.xml} (63%)

diff --git a/.springBeans b/.springBeans
new file mode 100644
index 0000000..2bef418
--- /dev/null
+++ b/.springBeans
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beansProjectDescription>
+	<version>1</version>
+	<pluginVersion><![CDATA[3.2.0.201301251408-M2]]></pluginVersion>
+	<configSuffixes>
+		<configSuffix><![CDATA[xml]]></configSuffix>
+	</configSuffixes>
+	<enableImports><![CDATA[false]]></enableImports>
+	<configs>
+		<config>src/main/webapp/WEB-INF/mvc-core-config.xml</config>
+	</configs>
+	<configSets>
+	</configSets>
+</beansProjectDescription>
diff --git a/src/main/webapp/WEB-INF/mvc-core-config.xml b/src/main/webapp/WEB-INF/mvc-core-config.xml
new file mode 100644
index 0000000..6ce11a4
--- /dev/null
+++ b/src/main/webapp/WEB-INF/mvc-core-config.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+	- DispatcherServlet application context for PetClinic's web tier.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
+	xmlns:oxm="http://www.springframework.org/schema/oxm" xmlns:mvc="http://www.springframework.org/schema/mvc"
+	xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
+		http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm.xsd
+		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
+
+	<import resource="mvc-view-config.xml"/>
+	
+	<!--
+		- POJOs labeled with the @Controller and @Service annotations are auto-detected.
+	-->
+	<context:component-scan base-package="org.springframework.samples.petclinic.web, org.springframework.samples.petclinic.service"/>
+	
+	 <mvc:annotation-driven  conversion-service="conversionService"/>
+	
+	<!--  all resources inside folder src/main/webapp/resources are mapped so they can be refered to inside JSP files
+		(see header.jsp for more details) -->
+	<mvc:resources mapping="/resources/**" location="/resources/"/>
+	
+	<!-- uses WebJars so Javascript and CSS libs can be declared as Maven dependencies (we're using it for Bootstrap) -->
+	<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>
+	
+	<mvc:view-controller path="/" view-name="welcome"/>
+	
+	
+	<bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
+		<property name="formatters">
+			<set>
+				<bean class="org.springframework.samples.petclinic.web.PetTypeFormatter" />
+			</set>
+		</property>
+	</bean>
+	
+	<!--
+		- Message source for this context, loaded from localized "messages_xx" files.
+		- Files are stored inside src/main/resources
+	-->
+	<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"
+			p:basename="messages/messages"/>
+
+	<!--
+		- This bean resolves specific types of exceptions to corresponding logical 
+		- view names for error views. The default behaviour of DispatcherServlet 
+		- is to propagate all exceptions to the servlet container: this will happen 
+		- here with all other types of exceptions.
+	-->
+	<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
+		<property name="defaultErrorView" value="exception"/>
+		<property name="warnLogCategory" value="warn"/>
+	</bean>
+
+</beans>
diff --git a/src/main/webapp/WEB-INF/petclinic-servlet.xml b/src/main/webapp/WEB-INF/mvc-view-config.xml
similarity index 63%
rename from src/main/webapp/WEB-INF/petclinic-servlet.xml
rename to src/main/webapp/WEB-INF/mvc-view-config.xml
index 485b73d..a4e089e 100644
--- a/src/main/webapp/WEB-INF/petclinic-servlet.xml
+++ b/src/main/webapp/WEB-INF/mvc-view-config.xml
@@ -10,34 +10,8 @@
 		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
 		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
 
+
 	<!--
-		- The controllers are autodetected POJOs labeled with the @Controller annotation.
-	-->
-	<context:component-scan base-package="org.springframework.samples.petclinic.web, org.springframework.samples.petclinic.service"/>
-	
-	
-	 <mvc:annotation-driven  conversion-service="conversionService"/>
-	
-	<!--  all resources inside folder src/main/webapp/resources are mapped so they can be refered to inside JSP files
-		(see header.jsp for more details) -->
-	<mvc:resources mapping="/resources/**" location="/resources/"/>
-	
-	<!-- uses WebJars so Javascript and CSS libs can be declared as Maven dependencies (we're using it for Bootstrap) -->
-	<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>
-	
-	<mvc:view-controller path="/" view-name="welcome"/>
-	
-	
-	<bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
-		<property name="formatters">
-			<set>
-				<bean class="org.springframework.samples.petclinic.web.PetTypeFormatter" />
-			</set>
-		</property>
-	</bean>
-	
-	
-<!--
 		- This view resolver delegates to the InternalResourceViewResolver and BeanNameViewResolver,
 		- and uses the requested media type to pick a matching view. When the media type is 'text/html',
 		- it will delegate to the InternalResourceViewResolver's JstlView, otherwise to the
@@ -78,28 +52,8 @@
 	-->
 	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/"
 			p:suffix=".jsp" p:order="2"/>
-			
-	<!--
-		- Message source for this context, loaded from localized "messages_xx" files.
-		- Files are stored inside src/main/resources
-	-->
-	<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"
-			p:basename="messages/messages"/>
-
-	<!--
-		- This bean resolves specific types of exceptions to corresponding logical 
-		- view names for error views. The default behaviour of DispatcherServlet 
-		- is to propagate all exceptions to the servlet container: this will happen 
-		- here with all other types of exceptions.
-	-->
-	<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
-		<property name="defaultErrorView" value="exception"/>
-		<property name="warnLogCategory" value="warn"/>
-	</bean>
-
-
-	<!-- 	- The AtomView rendering a Atom feed of the visits  -->
-	 
+	
+	<!-- 	- The AtomView rendering a Atom feed of the visits  -->	 
 	<bean id="visitsList" class="org.springframework.samples.petclinic.web.VisitsAtomView"/>
 
 	<bean id="vets/vetsList" class="org.springframework.web.servlet.view.xml.MarshallingView">
diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml
index e1ea993..7162fdc 100644
--- a/src/main/webapp/WEB-INF/web.xml
+++ b/src/main/webapp/WEB-INF/web.xml
@@ -1,39 +1,22 @@
 <?xml version="1.0" encoding="ISO-8859-1"?>
-<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 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
+id="WebApp_ID" version="2.5">
 
 	<display-name>Spring PetClinic</display-name>
-
 	<description>Spring PetClinic sample application</description>
-
-	<!--
-		Key of the system property that should specify the root directory of this
-		web app. Applied by WebAppRootListener or Log4jConfigListener.
-	-->
-	<context-param>
-		<param-name>webAppRootKey</param-name>
-		<param-value>petclinic.root</param-value>
-	</context-param>
 	
 	 <context-param> 
 	    <param-name>spring.profiles.active</param-name>
 	    <param-value>jdbc</param-value>
-	    <!-- you can replace the above param with:
+	    <!-- Available profiles:
 	    	<param-value>jdbc</param-value>
 	    	<param-value>jpa</param-value> (in the case of plain JPA)
 	    	<param-value>spring-data-jpa</param-value> (in the case of Spring Data JPA)
 	     -->
 	  </context-param>
 
-	<!--
-		Location of the Log4J config file, for initialization and refresh checks.
-		Applied by Log4jConfigListener.
-	-->
-	<context-param>
-		<param-name>log4jConfigLocation</param-name>
-		<param-value>/WEB-INF/classes/log4j.xml</param-value>
-	</context-param>
-
 	<!--
 		- Location of the XML file that defines the root application context.
 		- Applied by ContextLoaderServlet.
@@ -41,66 +24,33 @@
 	<context-param>
 		<param-name>contextConfigLocation</param-name>
 		<param-value>classpath:spring/applicationContext-dao.xml</param-value>
-		<!--
-			To use the JPA variant above, you will need to enable Spring load-time
-			weaving in your server environment. Out of the box, Spring will try to
-			detect the running environment and use the appropriate weaver but if that
-			fails, one must enable one by hand or use the VM-wide weaver.
-			See PetClinic's readme and/or Spring's JPA documentation for more information.
-		-->
 	</context-param>
 	
 	<listener>
 		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 	</listener>	
-
-	<!--
-		- Configures Log4J for this web app.
-		- As this context specifies a context-param "log4jConfigLocation", its file path
-		- is used to load the Log4J configuration, including periodic refresh checks.
-		-
-		- Would fall back to default Log4J initialization (non-refreshing) if no special
-		- context-params are given.
-		-
-		- Exports a "web app root key", i.e. a system property that specifies the root
-		- directory of this web app, for usage in log file paths.
-		- This web app specifies "petclinic.root" (see log4j.properties file).
-	-->
-	<!-- Leave the listener commented-out if using JBoss -->
-	<!--
-	<listener>
-		<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
-	</listener>
-	-->
 	
 	<!--
 		- Servlet that dispatches request to registered handlers (Controller implementations).
-		- Has its own application context, by default defined in "{servlet-name}-servlet.xml",
-		- i.e. "petclinic-servlet.xml".
-		-
-		- A web app can contain any number of such servlets.
-		- Note that this web app has a shared root application context, serving as parent
-		- of all DispatcherServlet contexts.
 	-->
 	<servlet>
 		<servlet-name>petclinic</servlet-name>
 		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
+		<init-param>
+			<param-name>contextConfigLocation</param-name>
+			<param-value>/WEB-INF/mvc-core-config.xml</param-value>
+		</init-param>
 		<load-on-startup>1</load-on-startup>
 	</servlet>
 
-	<!--
-		- Maps the petclinic dispatcher to "*.do". All handler mappings in
-		- petclinic-servlet.xml will by default be applied to this subpath.
-		- If a mapping isn't a /* subpath, the handler mappings are considered
-		- relative to the web app root.
-		-
-		- NOTE: A single dispatcher can be mapped to multiple paths, like any servlet.
-	-->
 	<servlet-mapping>
 		<servlet-name>petclinic</servlet-name>
 		<url-pattern>/</url-pattern>
 	</servlet-mapping>
 
+	<!-- used so we can use forms of method type 'PUT' and 'DELETE' 
+	see here: http://static.springsource.org/spring/docs/current/spring-framework-reference/html/view.html#rest-method-conversion
+	-->
 	<filter>
 		<filter-name>httpMethodFilter</filter-name>
 		<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
@@ -110,9 +60,5 @@
 		<filter-name>httpMethodFilter</filter-name>
 		<servlet-name>petclinic</servlet-name>
 	</filter-mapping>
-
-	<session-config>
-		<session-timeout>10</session-timeout>
-	</session-config>
 	
 </web-app>
\ No newline at end of file
-- 
GitLab