Reputation: 1072
Consider below code:
<bean id="busmessageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<list>
<value>classpath:bundles/resource</value>
<value>classpath:bundles/override</value>
<value>file:/C:/mmt/override</value>
</list>
</property>
<property name="cacheSeconds" value="100" />
</bean>
Here properties from bundles/resource
and bundles/override
get fetched when I call busmessageSource.getMessage("anykey", null, null)
but it fails when I try to fetch values for properties in C:/mmt/override
file:/C:/mmt/override
to override values in classpath:bundles/override
if any with the same key exist. How do I override properties from an external file outside of my war folder?Upvotes: 4
Views: 14769
Reputation: 4717
I ran into similar question (by the title of your question) and managed to instantiate Spring ResourceBundleMessageSource with java.util.Properties
.
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setCommonMessages(properties);
Kind of naive approach, but did the job for my unit testing.
Upvotes: 1
Reputation: 1000
You can try
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="defaultEncoding" value="UTF-8"/>
<property name="basenames">
<list>
<value>classpath:bundles/resource</value>
<value>classpath:bundles/override</value>
<value>file:C:/mmt/override</value>
</list>
</property>
</bean>
About message resource keep note:
Upvotes: 5
Reputation: 310
1.) I have these 3 ways:
C:/mmt/
" folder to your resource classpath.<beans:bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<beans:property name="basename">
<beans:value>file:/path/to/messages</beans:value>
</beans:property>
</beans:bean>
Note1: You must use the } file:
prefix and the ReloadableResourceBundleMessageSource
class.
Note2: Do not put the ".properties" extension.
2.) You override previous values when you load a new properties file with same property names (keys). You must ensure that you fetch last the properties file you want to use.
Upvotes: 9