<?xml version="1.0" encoding="UTF-8"?>
<!--
    Copyright 2002-2013 the original author or authors.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->

<!--
    - DispatcherServlet application context for PetClinic's web tier.
-->
<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:mvc="http://www.springframework.org/schema/mvc"
       xmlns="http://www.springframework.org/schema/beans"
       xsi:schemaLocation="http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.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"/>

    <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 staticFiles.jsp for more details) -->
    <mvc:resources mapping="/resources/**" location="/resources/"/>
    <mvc:resources mapping="/vendors/**" location="/vendors/"/>

    <mvc:view-controller path="/" view-name="welcome"/>

    <!-- serve static resources (*.html, ...) from src/main/webapp/
    Required when both servlet-mapping is '/' and static resources need to be served -->
    <mvc:default-servlet-handler/>

    <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.
    -->
    <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
        <!-- view name resolved using bean of type InternalResourceViewResolver (declared in mvc-view-config.xml) -->
        <property name="defaultErrorView" value="exception"/>
        <!-- results into 'WEB-INF/jsp/exception.jsp' -->
        <property name="warnLogCategory" value="warn"/>
        <!-- needed otherwise exceptions won't be logged anywhere -->
    </bean>

</beans>
