Reloading of properties file which is loaded using setBundle

gok-nine picture gok-nine · Nov 9, 2010 · Viewed 7.4k times · Source

I was hoping for a little help with a problem I am having involving properties files in Spring. So the setup I have is like so:

opto-mapping.properties – this is located in my src folder and contains translations for my optimised resources like so:

generic-min.css=4037119659.css

This properies file is updated every time the build ‘optimise’ is run. I then use

<fmt:setBundle basename="opto-mapping" />

To import my properties file in my desired jsp. Then referencing the content by using:

<fmt:message key='generic-min.css' />

This all works beautifully except that the properties file requires a tomcat restart to be reloaded. I dont want to have to start taking sites down everytime a resource is updated. I would like the properties file to automatically reload every so often.

I did attempt to update an existing bean in my spring-context.xml to reload this properties file like I do with translations but this has not worked - more than likely because of the opto-mapping.properties files location - but you see it needs to be in that location to load using fmt:setBundle.

<bean id="messageSource"
        class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="cacheSeconds">
            <value>1</value>
        </property>
        <property name="basenames">
            <list>
                <value>WEB-INF/translations/translations</value>
                <value>WEB-INF/classes/opto-mapping</value>
            </list>
        </property>
</bean>

Any help or a point in the right direction would be greatly appreciated in this difficult time.

I hope all this makes senese and many thanks in advance!

G.

Answer

gok-nine picture gok-nine · Nov 11, 2010

Thank you both for your responses. I have now got this working and thought I would share the wealth.

So, I moved my properties file out of the src folder and into WEB-INF/properties.

I updated the following bean to load up the properties files:

<bean id="messageSource"
        class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="cacheSeconds">
            <value>1</value>
        </property>
        <property name="basenames">
            <list>
                <value>WEB-INF/translations/translations</value>
                <value>WEB-INF/properties/opto-mapping</value>
            </list>
        </property>
    </bean>

Now, previously I was using setBundle to load into my properties file like this:

<fmt:setBundle basename="opto-mapping" />

But I found that obviously my properties file wasnt being loaded anymore because I had moved it. But because of my bean setup the new properties file was being loaded but my setBundle was overwritting that.

So, the solution was to remove the setBundle and now my properties file is reloading!

Thanks again!