mahi mahi - 3 years ago 101
Java Question

Update the default locale value by using properties file in Spring MVC

My plan is to update the default locale value in servlet-context.xml with the value of messages.properties file. Verified the other StackOverflow questions and other links as well, but not the success.

servlet-context.xml is,

<context:property-placeholder location="C:\\Users\\Mahesh\\Downloads\\SpringInternalization\\src\\main\\resources\\messages.properties" />

<!-- Enables the Spring MVC @Controller programming model -->
<mvc:annotation-driven />

<mvc:resources mapping="/resources/**" location="/resources/" />

<!-- Resolves views selected for rendering by @Controllers to .jsp resources
in the /WEB-INF/views directory -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>

<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<!-- <property name="basename" value="classpath:messages" /> -->
<property name="basenames">
<list>
<value>classpath:messages</value>
</list>
</property>
<property name="defaultEncoding" value="UTF-8" />
</bean>

<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" >
<value>${property.language}</value>
</property>
</bean>

<!--
<mvc:interceptors>
<bean
class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang" />
</bean>
</mvc:interceptors>
-->
<context:component-scan base-package="com.jocata.spring" />


Please help on this guys. Thanks in advance.
Tried the following,

Use property file's property in spring mvc configuration servlet xml

Answer Source

What are your language file names? Why do you need to specify the absolute path of your properties file?

Try this

<context:property-placeholder location="classpath:messages.properties" />

OR use forward slash in your file path

<context:property-placeholder location="file:C:/Users/Mahesh/Downloads/SpringInternalization/src/main/resources/messages.properties" />
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download