I’m currently developing a web application. I know some basics of Spring, however I haven’t been working with it that much, hence I’ve decided to improve my Spring-skills and I’ve faced a problem that I can’t really find a good solution for.
I’d like to implement in my app a feature that will allow the user to configure everything without touching any config file (e.g. spring beans), basically the person that wants to deploy, launch and use the app should only copy the .WAR file into for example tomcat and all the configuration should be done within the app (like in OpenFire for example).
So I imagine that the user deploys the app goes to certain URL and everything is done through UI, he is being asked about some parameters (e.g. DB connection details) once all details are given everything is stored in cfg file, app restarted and the configuration process is over.
I wanted to have all the configuration details in spring beans, but I’ve discovered that I can’t really change them programmatically (one solution would be to modify the file ‘out of spring’ and reload the app context after wards – is that good approach?).
Another one would be to store xml file in WEB-INF for example and save the data there once it’s gathered from the user, but then how to load the data from non-bean file into application context?
Any advices appriciated!
You can keep such values in properties file. You can use property file values in spring bean.
Also you can update values in properties file with user input accepted through UI.