-
May 10th, 2012, 02:26 PM
#1
Spring Message bundle not getting destroyed
Hi,
I have a resource bundle ( error messages ) which I am loading through spring container. I have a requirement where in through a MBean i should destroy the exisitng message bundle and copy the the bundle from a folder and load into the container fresh. For some reason, The bundle is not getting destroyed even after closing the application context and creating it brand new. When i did the code inspection, what i found is that its still holding the reference to the old message resource some how.
Here is the config file
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schem...ng-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id="messageSource"
class="org.springframework.context.support.Resourc eBundleMessageSource">
<property name="basename">
<value>errors</value>
</property>
</bean>
</beans>
i have this config and errors_en_US.properties in WEB-INF/classes folder.
Here is the java code:
DTLogger log = DTLogger.getLogger(ErrorMessages.class);
String configRoot = System.getProperty(AuctionConstants.CONFIGURATION_ ROOT);
String errorResourceBundle = "errors_" + Locale.getDefault() + ".properties";
File file = new File(configRoot + errorResourceBundle);
log.info("Loading the resource bundle " + configRoot + errorResourceBundle);
if (!file.exists())
{
log.error("Reosurce bundle does not exist : " + configRoot + errorResourceBundle);
throw new SystemException(DTExceptionCodes.SE000016,
new Object[] { configRoot + errorResourceBundle });
}
String applicationRoot = System.getProperty(AuctionConstants.APPLICATION_RO OT);
String targetPath = applicationRoot + "/WEB-INF/classes";
try
{
FileUtils.copyFileToDirectory(new File(configRoot + errorResourceBundle),
new File(targetPath));
}
catch (IOException e)
{
log.error(e.getStackTrace());
throw new SystemException(e);
}
((ClassPathXmlApplicationContext)MessageContainer. getMessageContext()).close(); // this should destroy the application context
MessageContainer.initialize(); // this will create a brand new application context
log.info("Loading of " + errorResourceBundle + " Done.");
any help in this regard will be greatly appreciated.
Thanx and Regards
KR Kumar
-
May 11th, 2012, 01:14 AM
#2
Please use [ code][/code ] tags when posting code.
The behavior you describe is the way resource bundles work, once loaded they don't reload. Hence the existence of the ReloadableResourceBundleMessageSource which doesn't use ResourceBundles but mimicks the behavior. Simple get the MessageSource call clear cache and you are done, no need to destroy and recreate application contexts...
-
May 11th, 2012, 11:41 AM
#3
Hi,
Thanx for the suggession. Unless I am missing something, there is no method on the ResourceBundleMessageSource to clear the cache and the hasmap thats holding the bundles is a private member in the class, so I cannot extend and have access to it.
Thanx and Regards
KR Kumar
-
May 14th, 2012, 01:13 AM
#4
Reading seems to be an art.. I suggested to use the ReloadableResourceBundleMessageSource and even pointed you to the javadocs which clearly indicate a public available method clearcache.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules