좋은 프로그램은 마음의 여유에서 나온다.

스프링 다국어 설정 본문

프로그래밍/Spring

스프링 다국어 설정

좋은데이 2014. 5. 9. 15:40

lang 파라미터로 언어 변경 안되는 경우


아래의 코드에서 handlerMapping을 제거하고 localChangeInterceptor을 mvc:interceptor 안에 추가


<beans:bean id="messageSource"

    class="org.springframework.context.support.ReloadableResourceBundleMessageSource">

    <beans:property name="basename" value="/WEB-INF/messages/messages" />

    <beans:property name="defaultEncoding" value="UTF-8"/>

</beans:bean>

<beans:bean id="localeChangeInterceptor"

    class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">

    <beans:property name="paramName" value="lang" />

</beans:bean>

<beans:bean id="localeResolver"

    class="org.springframework.web.servlet.i18n.CookieLocaleResolver">

</beans:bean>

<beans:bean id="handlerMapping"

    class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">

    <beans:property name="interceptors">

<beans:ref bean="localeChangeInterceptor"/>

        </beans:property>

</beans:bean>


수정된 내용


<beans:bean id="messageSource"

    class="org.springframework.context.support.ReloadableResourceBundleMessageSource">

    <beans:property name="basename" value="/WEB-INF/messages/messages" />

    <beans:property name="defaultEncoding" value="UTF-8"/>

</beans:bean>

<mvc:interceptors>

<beans:bean id="localeChangeInterceptor"

    class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">

    <beans:property name="paramName" value="lang" />

</beans:bean>

</mvc:interceptors>

<beans:bean id="localeResolver"

    class="org.springframework.web.servlet.i18n.CookieLocaleResolver">

</beans:bean>


참고 : http://stackoverflow.com/questions/18287711/spring-mvc-3-localechangeinterceptor

Comments