using properties file in spring java mvc along with xml files

Rohit Bajaj
Rohit Bajaj used Ask the Experts™
I have a spring java project i found that its using two files :
1) database.xml

The file specify the jdbc url and username and password
These properties are then used in database.xml file with the notation "${}" to access the jdbc url and username and password

My question is why create the file in the first place ? arent xml files also non compiled and so one can directly edit them without restarting the server ?
Is it just for a readability purpose or there are some other significance of using this pattern ?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
yes u r correct
if we use database. properties we can do modifications if required with out disturbing the application,no need to restart the server.
if we use directly database. xml with out using file
we need to restart the server,if any modification required.


what is the exact reason.
1) why server restart is not required when changing properties file?
2) why it is required when xml is changed ?
i have read somewhere that there are hot deployment ways. like using jrebel etc which automatically handles any change....i think using that does not require server restart
properties file no need to compile
where as xml we need to recompile and restart the server.
IT Business Systems Analyst / Software Developer
Top Expert 2015
I think it is more just for readability. It is much easier to look at what is probably only a couple of lines in the .properties file than to sift through maybe 10's or 100's of lines in the .xml file. Also it is much easier to create big problems by incorrectly editing the .xml file than it is if you botched up the .properties file. And another issue that I can think of, is that there are more special, interpreted characters in XML. Just one that I can think of that would be common in a DB URL is the & character. If this were directly in the .xml file, the person editing would have to remember to use the full XML character entity like this... & to make the XML parser happy, where as if it is in the .properties file you can just use & directly.
mccarlIT Business Systems Analyst / Software Developer
Top Expert 2015

As to what support the application has for HOT changes to those setting, it is still a case-by-case basis. As you have it now, where those properties are used by the XML with ${} placeholders, without further external support you STILL need to restart the server for any changes to those DB parameters.

However, there are other cases where you CAN easily support HOT changes to .properties file without needing server restarts, and you could do this easier than having the changes applied to the .xml file.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial