petclinic-servlet.xml

124 lines | 5.452 kB Blame History Raw Download
<?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">

	<!--
		- The controllers are autodetected POJOs labeled with the @Controller annotation.
	-->
	<context:component-scan base-package="org.springframework.samples.petclinic.web"/>

	<!--
		- The form-based controllers within this application provide @RequestMapping 
		- annotations at the type level for path mapping URLs and @RequestMapping 
		- at the method level for request type mappings (e.g., GET and POST). 
		- In contrast, ClinicController - which is not form-based - provides 
		- @RequestMapping only at the method level for path mapping URLs.
		-
		- DefaultAnnotationHandlerMapping is driven by these annotations and is 
		- enabled by default with Java 5+.
	-->
	
	<!--
		- This bean processes annotated handler methods, applying PetClinic-specific PropertyEditors
		- for request parameter binding. It overrides the default AnnotationMethodHandlerAdapter.
	-->
	 <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
		<property name="webBindingInitializer"> 
			<bean class="org.springframework.samples.petclinic.web.ClinicBindingInitializer"/>
		</property>
	</bean>

	<!--
		- 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="exceptionMappings">
			<props>
				<prop key="org.springframework.web.servlet.PageNotFound">pageNotFound</prop>
				<prop key="org.springframework.dao.DataAccessException">dataAccessFailure</prop>
				<prop key="org.springframework.transaction.TransactionException">dataAccessFailure</prop>
			</props>
		</property>
		<property name="defaultErrorView" value="uncaughtException"/>
	</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
		- BeanNameViewResolver. Note the use of the expression language to refer to the contentType
		- property of the vets view bean, setting it to 'application/vnd.springsource.samples.petclinic+xml'.
	-->
	
	<mvc:annotation-driven content-negotiation-manager="contentNegotiationManager" /> 

	<mvc:resources mapping="/resources/**" location="/resources/"/>
	
	<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>
	

	<bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
	    <property name="favorPathExtension" value="false" />
	    <property name="favorParameter" value="true" />
	    <property name="mediaTypes">
	        <value>
	            atom=application/atom+xml
	            html=text/html
	            xml=application/xml
	        </value>
	    </property>
	</bean>

	
	<!--
		- The BeanNameViewResolver is used to pick up the visits view name (below).
		- It has the order property set to 1, which means that this will
		- be the first view resolver to be used after the delegating content
		- negotiating view resolver.
	 -->
	<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />
	<!--

		- This bean configures the 'prefix' and 'suffix' properties of
		- InternalResourceViewResolver, which resolves logical view names
		- returned by Controllers. For example, a logical view name of "vets"
		- will be mapped to "/WEB-INF/jsp/vets.jsp".
	-->
	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/"
			p:suffix=".jsp" />

	
	<!-- 	- The AtomView rendering a Atom feed of the visits  -->
	 
	<bean id="visits" class="org.springframework.samples.petclinic.web.VisitsAtomView"/>

	<bean id="vets" class="org.springframework.web.servlet.view.xml.MarshallingView">
		<property name="contentType" value="application/vnd.springsource.samples.petclinic+xml"/>
		<property name="marshaller" ref="marshaller"/>
	</bean>

	<oxm:jaxb2-marshaller id="marshaller">
		<oxm:class-to-be-bound name="org.springframework.samples.petclinic.Vets"/>
	</oxm:jaxb2-marshaller>

	<!--
		- Message source for this context, loaded from localized "messages_xx" files.
		- Could also reside in the root application context, as it is generic,
		- but is currently just used within PetClinic's web tier.
	-->
	<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"
			p:basename="messages"/>

</beans>