Reputation: 1429
I have a Spring (maven) project in which I am using property file. This property file contains UI labels and messages. In source code property file location is src/main/resources/message/ApplicationResources.properties Output of this project is WAR file. Location of the property file inside war is WEB-INF/classes/message/ApplicationResources.properties
I am trying to use this property file like below
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<value>classpath*:message/ApplicationResources</value>
</property>
</bean>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>classpath*:message/ApplicationResources</value>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
</bean>
But every time I am getting below exception
Caused by: org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [message/ApplicationResources] cannot be opened because it does not exist
at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:89)
I did lot of google and tried almost all the options but nothing worked for me. With few options
javax.servlet.ServletException: javax.servlet.jsp.JspTagException: NoNo message found under code 'label.meetingDescription' for locale 'en_US'
Upvotes: 1
Views: 794
Reputation: 1632
I've faced some similar problems and finally get it to work pointing to the resources file name, not specifying a directory. My example uses several files but it's almost the same:
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames" value="classpath:applicationMessages,classpath:ValidationMessages"/>
</bean>
Upvotes: 0
Reputation: 1429
Finally I figured out the solution. Below configurations worked for me.
<context:property-placeholder location="classpath:message/ApplicationResources.properties"/>
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames" value="WEB-INF/classes/message/ApplicationResources"/>
</bean>
Upvotes: 0
Reputation: 771
If your ApplicationMessage.properties is in src/main/resources/message you have to use
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<value>classpath*:/message/ApplicationResources</value>
</property>
</bean>
(be careful of /message/).
If you don't use / at the beginning of the classpath it 's referering to current folder. With / it's the root folder of the classpath (aka src/main/resources)
Upvotes: 0
Reputation: 4361
Please try to change your configuration to:
<property name="locations">
<list>
<value>classpath*:message/ApplicationMessages.properties</value>
</list>
</property>
or
<property name="location">
<value>classpath*:message/ApplicationMessages.properties</value>
</property>
Upvotes: 1