Search code examples
javaspringspring-mvcjbossresourcebundle

Spring ResourceBundleMessageSource is not loading a property file from a jar while ClassPathResource can


I am trying to load a message.properties file from a jar file, but it is not finding the file (and I have been trying for a few hours).

<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basenames">
        <list>
            <value>messages/messages</value>
            <value>classpath:org/common/messages/messages</value>
        </list>
    </property>
</bean>

But it cannot find it:

[org.springframework.context.support.ResourceBundleMessageSource] (http-/0:0:0:0:0:0:0:0:8080-5) ResourceBundle [classpath:org/common/messages/messages] not found for MessageSource: Can't find bundle for base name classpath:org/common/messages/messages, locale en_US

I have tried the following, and it does load the file, which I assume means the file is on the classpath

ClassPathResource cpr = new ClassPathResource("org/common/messages/messages.properties");

What is the difference?

I am running this on JBoss.


Solution

  • Try this sample, from this POST - Spring UTF-8 message resource from external jar proglem

    <bean id="propertiesMessageSource"
    class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basename" value="classpath:com/mypackage/i18n/messages" />