더북(TheBook)

5. servlet-context.xml 파일에 유효성 검사 관련 빈을 설정합니다.

코드13-22 servlet-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans...>
    ...
<annotation-driven enable-matrix-variables="true" validator="validator"/> 
    ...
<beans:bean id="messageSource"
            class="org.springframework.context.support.ResourceBundleMessageSource">
    <beans:property name="basename" value="messages"/>
    <beans:property name="defaultEncoding" value="UTF-8"/>
</beans:bean>

<beans:bean id="validator" 

            class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
    <beans:property name="validationMessageSource" ref="messageSource"/>
</beans:bean>

 

<beans:bean id="unitsInStockValidator"
            class="com.springmvc.validator.UnitsInStockValidator"/> 

<beans:bean id="bookValidator" class="com.springmvc.validator.BookValidator">
    <beans:property name="springValidators">
        <beans:set>
            <beans:ref bean="unitsInStockValidator"/>
        </beans:set>
    </beans:property>
</beans:bean>
</beans:beans...>
신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.