PDA

View Full Version : Cannot read ApplicationResources.properties.Please Help!


jkookie
Aug 29th, 2005, 03:33 PM
Hi everybody, I can't seem to find a solution to this for a few days now. I can't read off of the ApplicationResources.properties file.
Here is how i have my application configured.
web.xml


<servlet>
<servlet-name>xxx</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>webAppName</param-name>
<param-value>xxx</param-value>
</init-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListe ner</listener-class>
</listener>
<init-param>
<param-name>application</param-name>
<param-value>ApplicationResources</param-value>
</init-param>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:xxx-frm-config.xml</param-value>
</init-param>
<init-param>
<param-name>namespace</param-name>
<param-value>xxx-frm-config</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>


Code from my xxx-frm-config.xml


<bean id="messageSource" class="org.springframework.context.support.ReloadableReso urceBundleMessageSource">
<property name="basename" value="/WEB-INF/ApplicationResources.properties"/>
<property name="cacheSeconds" value="1"/>
</bean>


I have a form , for which i have a validator implemented. The validator has the following validation code ( relevant code) -


ValidationUtils.rejectIfEmptyOrWhitespace(errors, fld, "smtmMessage.sendersReference.req", "Customer Reference is required");


Now, i have "smtmMessage.sendersReference.req" mapped to a value in my messageResource. But spring doesn't seem to read the properties file.

I read a few posts on similar problems and, possible solutions involved the ContextLoaderListener (ContextLoader in a few cases). I tried moving the listener outside of the <servlet></servlet> tags(along with the contextConfigLoactions), like i have them now. But all that did is initialize all the beans in my xxx-frm-configxml file twice - once when loading the contextloaderlistener and again when loading the DispatcherServlet. And it still wasn't able to read the ApplicationResource file.

One thing to note was when i changed the 'ReloadableResourceBundleResource' to 'ResourceBundleResource' i got errors in my server console telling me that spring couldn't find the bundle with basename '/WEB-INF/ApplicationResources.properties', while this is exactly where the file is in the war file - no typo no nothing.
This is the log from when i start my server and spring initializes the messageResouce -

Aug-29-2005 18:49:09 INFO (AbstractBeanFactory.java:222) - Creating shared instance of singleton bean 'messageSource'
Aug-29-2005 18:49:09 INFO (AbstractApplicationContext.java:413) - Using MessageSource [org.springframework.context.support.R
eloadableResourceBundleMessageSource: basenames=[/WEB-INF/ApplicationResources.properties]]


My xxx-frm-config.xml file doesn't reside in the war file but in a differnent config directory. I tried removing the /WEB-INF/ in my specification for the message source and put the applicationresource.properties file in the same folder as that of the xxx-frm-config.xml. This didn't change anything. :(
Any help, any suggestions? I'm running into a dead end here. This is getting to be very frustrating.
Thanks in advance.

jkookie
Aug 30th, 2005, 08:17 AM
Hi, anybody? All typemismatch errors appear in an ugly format on my form on bind errors. I still can't seem to get spring read of the properties file for meaningful errors.
:(

jkookie
Aug 30th, 2005, 10:35 AM
Phew, i created another applicationContext file and loaded that using the contextLoadListener, and moved the message resource bean spec from my xxx-frm-config.xml to the applicationContext.xml and spring can read the resource file.
Hallelujah!!