Changing properties in spring.properties dynamically without having to rebuild the .war?
I seem to have run into an issue in what I am trying to do. I have been writing an automation app that is supposed to run a new instance of our Spring MVC application (on a newly created cloud server instance). I thought that if I just made this automatio开发者_如何学JAVAn app unzip my .war
after downloading it and then change the info in the spring.properties
to match my datbase settings, etc then it should work fine. However, this seems to be causing some major problem as the app won't load using Tomcat after I do do this (gives errors about register JDBC and just hangs). It works fine if I put in the spring.properties
settings I want before building the .war
and then just run the .war
normally within Tomcat.
I'm hoping someone could shed some light on why this issue may be occurring and / or what I can do so that I can dynamically set the properties in spring.properties before running a .war
file without having to build the .war
with new settings (as this would add more hassle to everything).
Option 1: Use context:property-placeholder and override values using System Property at run-time.
Option 2: Read run-time properties from a file external to the war
6 Tips for Managing Property Files with Spring
So, perhaps this is not the correct answer, but if you're trying to externalize your datasource, then you should use JNDI with Tomcat. It's much cleaner. You just use the jee namespace with spring then to lookup your datasource. This way the server admins can setup the datasource within server.xml :)
精彩评论