Kidades
Kidades

Reputation: 670

Not able to find messages with ResourceBundleMessageSource

I am currently using the following code which is working correctly:

<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basenames">
            <list>
                <value>/WEB-INF/resources/lang/lang</value>
            </list>
        </property>
        <property name="defaultEncoding" value="UTF-8"/>
    </bean>

When I change ReloadableResourceBundleMessageSource to just ResourceBundleMessageSource it stops working.

<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basename" value="/WEB-INF/resources/lang/lang" />
</bean>

I keep getting exceptions saying "No message found under code 'title' for locale 'en_US'." (title is an example)

After reading similar questions, I have also tried changing the value of basename parameter to any of the following, without success: WEB-INF/resources/lang/lang .WEB-INF.resources.lang.lang
WEB-INF.resources.lang.lang
resources.lang.lang
lang.lang
lang
classpath:resources.lang.lang

enter image description here

Making a file called lang_en_US.properties didn't help either.

Upvotes: 0

Views: 1025

Answers (1)

Kidades
Kidades

Reputation: 670

Apparently, it is looking in the java folder (root of classpath) and not the web folder.

I created a new package called lang in the java folder and moved the lang*.properties files to it.

Then I put lang.lang as the value for basename and it started to work.

UPDATE: This stopped working after a project clean. The lang files should go into the "resources" folder, not the java folder. They technically end up in the same place after a build, but the IDE seems to ignore non-class files in the java folder and simply skips them.

enter image description here

Upvotes: 1

Related Questions