1. 程式人生 > >hibernate-validator.xml配置檔案

hibernate-validator.xml配置檔案

<?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-4.3.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-4.3.xsd
       http://www.springframework.org/schema/mvc
       http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
       ">
    <context:component-scan base-package="sps.controller"/>
    <context:annotation-config/>

    <mvc:annotation-driven validator="validator"/>

    <mvc:default-servlet-handler /> 
    <bean id="requestHandler" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
        <property name="useSuffixPatternMatch" value="false"/><!--關閉自動使用 .* 字尾-->
    </bean>
    <bean id="requestAdapter" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">    
        <property name="synchronizeOnSession" value="true"/>
    </bean>

    <!--
    配置DispatcherServlet的檢視解析器
    -->
    <bean id="internalresolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/"/>
        <property name="suffix" value=".jsp"/>
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
        <property name="exposeContextBeansAsAttributes" value="true"/>
    </bean>

    <bean id="hibernate_validator_messages" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basenames">
            <list>
                <value>/WEB-INF/hibernate_validator_messages/hibernate_validator_message_zh_CN</value>
            </list>
        </property>
        <property name="fileEncodings">
            <props>
                <prop key="/WEB-INF/hibernate_validator_messages/hibernate_validator_message_zh_CN">UTF-8</prop>
            </props>
        </property>
    </bean>
    <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
        <property name="providerClass" value="org.hibernate.validator.HibernateValidator" />
        <property name="validationMessageSource" ref="hibernate_validator_messages"/>
    </bean>
    
</beans>