How to configure messages.properties in spring bean annotation?

I am starting a new project with spring 4 and I am confusing how I can map my i18n file: messages.properties..

In spring 3 I was using xml configuration like this:

<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver" />
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basenames" value="messages" />
</bean>
<bean id="i18n" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    <property name="locations">
        <list>
            <value>classpath:/..../messages.properties</value>
        </list>
    </property>
    <property name="ignoreResourceNotFound" value="true" />
</bean>

And in my jsps files I access it by:

<spring:message code="any key" />

In spring 4 I am avoiding to use xml configuration.. I tried the following:

@Bean
public ResourceBundleMessageSource messageSource() throws Exception {
    ResourceBundleMessageSource resourceBundleMessageSource = new ResourceBundleMessageSource();
    resourceBundleMessageSource.setBasename("message.properties");
    return resourceBundleMessageSource;
}

@Bean
public PropertiesFactoryBean propertiesFactoryBean() throws Exception {
    PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
    Resource resource = new ClassPathResource("messages.properties");
    propertiesFactoryBean.setLocation(resource);
    return propertiesFactoryBean;
}

That class is annotated with @Configuration, but apparently is missing anything..

When I try to access index.jsp, I receive the following exception:

org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspTagException: No message found under code 'application.title' for locale 'pt_BR'.

Any help is appreciated.

Thanks

Answers


try

<spring:message code="myMessage"/> with <fmt:message key="myMessage"/>

and on web.xml

<context-param>
  <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
  <param-value>messages</param-value>
</context-param>

dont forget to add fmt taglib


Need Your Help

How to generate hex sequence in Swift?

swift hex

Hey guys I am trying to create a tool to calculate how many 6 bytes sequence it generates within a certain time set by me, like 10s or 1min and so on. The sequence, for example, is: 4F B0 33 47 A3 ...

asp.net mvc another controller in the same folder

javascript asp.net-mvc controller

I have a folder 'Report' which holds ReportController.