How to implement an auto reloadable XML using Apache VFS

XML is usually used to store light configuration that controls the business flow or the layout of an application, it’s meant to be managed by business users in the production phase due to its simple human-readable syntax.

A typical example is to store the default theme/layout of the application, control the accepted currencies of a financial application, turning on/off features of an application.

Since these configurations are prone to regular updates, it’s not practical to restart the application on each configuration change.

In this tutorial, we describe how to implement an auto reloadable XML using Apache VFS in Java.

1- app.xml

Suppose we have the following app.xml file which holds the business and layout configuration for our financial application:

2- pom.xml

In order to use Apache VFS, we add the following dependencies to pom.xml:


Create a POJO class named as which maps the attributes of app.xml:


Now, this is our configuration processor, we’ll create a class which loads the configuration at the application startup and listens for any runtime change on the XML file.

Our manager mainly acts as a cache and may be defined as a Singleton which populates AppConfiguration bean in the constructor and repopulates it on each XML change. Whenever we need to read the configuration from other classes or modules, we get an instance of the Cache and use AppConfiguration, hence any XML change will be reflected instantly on the application without the need for a restart.

Below is the implementation of XMLConfigurationManager:

As we notice, we read the configuration in the constructor and attach an event listener to the XML file using DefaultFileMonitor and FileListener classes provided by Apache VFS. On each change event, we call loadConfiguration() to repopulate the AppConfiguration bean.

Through this way, the latest version of XML would always be exposed to the application through XMLConfigurationManager and AppConfiguration bean.


0 0 votes
Article Rating

Hussein Terek

Owner of, I have a passion for software engineering and everything related to Java environment.

Inline Feedbacks
View all comments