Announcement Announcement Module
Collapse
No announcement yet.
ReloadableResourceBundleMessageSource Never works Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ReloadableResourceBundleMessageSource Never works

    Hi Team,

    I am trying to use org.springframework.context.support.ReloadableReso urceBundleMessageSource to reload resource bundle after edit some property. I see property edited by FileOutputStream but resource bundle never get refreshed. However I mentioned the cacheSeconds to 5 sec. I really appreciate if you help me on this. Thank You.

    <Code>
    package com.westernunion.risk.mercury.config;

    import static org.junit.Assert.*;

    import java.io.FileOutputStream;

    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.springframework.beans.factory.annotation.Autow ired;
    import org.springframework.context.support.ReloadableReso urceBundleMessageSource;
    import org.springframework.test.context.ContextConfigurat ion;
    import org.springframework.test.context.junit4.SpringJUni t4ClassRunner;

    @ContextConfiguration(locations={"classpath:META-INF/spring/reloadable-resource-bundle-test-context.xml"})
    @RunWith(SpringJUnit4ClassRunner.class)
    public class ReloadableResourceBundleTest {

    @Autowired
    private ReloadableResourceBundleMessageSource reloadableMessageSource;

    String FILE_NAME = "C:\\Users\\10594963\\workspace\\resource-bundle-poc\\src\\main\\java\\com\\abc\\resourcebundle\\me ssages.properties";

    @Test
    public void testReloableMessageProperty() throws Exception {
    FileOutputStream fos = null;
    try {
    String property1 = reloadableMessageSource.getMessage("vendor.admin.e ngg.property1", null, null);
    assertEquals(property1, "property1 value");

    System.out.println("property1 before update : "+property1);

    fos = new FileOutputStream(FILE_NAME);
    fos.write("vendor.admin.engg.property1=NEW VALUE".getBytes("UTF-8"));
    fos.close();

    Thread.sleep(15000);

    reloadableMessageSource.clearCache();

    property1 = reloadableMessageSource.getMessage("vendor.admin.e ngg.property1", null, null);

    System.out.println("property1 after update : "+property1);

    assertEquals("NEW VALUE", property1);


    } catch(Exception e) {
    e.printStackTrace();
    fos.close();
    } finally {

    }


    }
    }
    </Code>

    Spring context configuration file,
    <Code>
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="reloadableMessageSource" class="org.springframework.context.support.Reloada bleResourceBundleMessageSource">
    <property name="basenames">
    <list>
    <value>com/westernunion/risk/mercury/resourcebundle/messages</value>
    </list>
    </property>
    <property name="cacheSeconds" value="5"/>
    </bean>

    </beans>
    </Code>
Working...
X