Automatically change configuration based on the current environment
How to let the application knew its different running environments so it could change its configuration automatically based on the current one?
What if the application knew its different running environments so it could change its configuration automatically based on the current one?
If we wanted to do that, we had to solve 2 issues:
Fortunately for the second issue, we have Spring 3.1 which introduced the concept of profiles to bean definitions. This is similar to what Maven does to files but applied to beans.
Now, we can define different set of beans according to the current spring profile. If we structure our configuration in different sets of beans for each desired configuration we can change it easily.
The problem remains in how to detect the current environment to tell which spring profile to use. To know how, read this article!