Results 1 to 4 of 4

Thread: Spring Message bundle not getting destroyed

  1. #1

    Post 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

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    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...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3

    Default

    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

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •