Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reloading of properties file which is loaded using setBundle

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.

like image 256
gok-nine Avatar asked Nov 09 '10 17:11

gok-nine


People also ask

How do I reload the configuration properties without restarting the app?

web. exposure. include=refresh: this is actuator property which will help us to refresh the properties without restarting the server.

How do I refresh application properties in spring boot?

Reloading Properties by Actuator and Cloud Thus, we need Spring Cloud to add a /refresh endpoint to it. This endpoint reloads all property sources of Environment, and then publishes an EnvironmentChangeEvent. Spring Cloud has also introduced @RefreshScope, and we can use it for configuration classes or beans.

Do we need to restart server after changing properties file?

As expected, in case of any changes in the property files, we have to restart the weblogic server for the changes to take effect.

How load data from properties file?

The Properties file can be used in Java to externalize the configuration and to store the key-value pairs. The Properties. load() method of Properties class is convenient to load . properties file in the form of key-value pairs.


1 Answers

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!

like image 191
gok-nine Avatar answered Sep 21 '22 15:09

gok-nine