Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatic reloading of resources in Spring

Is there a way to automatically reload Spring resource file? I want to find out a simple way to change my configuration xml in runtime. Xml file is out of classpath folder.

Any ideas?

thx:)

like image 799
vlcik Avatar asked Jan 05 '12 14:01

vlcik


4 Answers

If you meant that you want to avoid redeploying your server to change your xml configuration, you can check JRebel http://zeroturnaround.com/jrebel/.

like image 101
Arnaud Gourlay Avatar answered Oct 31 '22 21:10

Arnaud Gourlay


If it is the app contest you want to refresh, use ConfigurableApplicationContext.refresh() or more specifically for the web environment , AbstractRefreshableWebApplicationContext . You could look this up using the context:property-placeholder .

like image 39
Aravind A Avatar answered Oct 31 '22 21:10

Aravind A


Create your own extension to the ResourceBundle interface and use that to look up your strings instead of Spring. This way, you can control things like reloading.

like image 1
Thom Avatar answered Oct 31 '22 20:10

Thom


Yes.

Spring provides ReloadableResourceBundleMessageSource that can reload the properties file through the cacheSeconds setting.It support the properties files in the format of *.properties and the XML format used by Properties.loadFromXML().

If your xml file is in other formats , you have to make your own resource loader by extending ReloadableResourceBundleMessageSource , and implement your logic to parse the XML file by overridding its loadProperties(Resource resource, String filename) .

like image 1
Ken Chan Avatar answered Oct 31 '22 19:10

Ken Chan