My preferred method of dealing with this situation is dependency injection (DI). Spring has a built-in DI function for which the tutorial is easy to find on the Internet . However, Spring DI is not as good for many reasons as Guice provides, which I would highly recommend. (The main advantage of Guice over Spring DI, in my opinion, is type safety.)
DI is basically a mechanism for replacing class implementations at runtime. Instead of hard code dependencies in classes (for example, if you have a class building other classes, for example), you encode them so that their dependent classes are passed to them in their constructors. The DI structure will then pass the correct instances at runtime as configured. Spring configuration can be done using annotations or an XML file; Guice uses a subclass of com.google.inject.AbstractModule .
Thus, you can use different configuration files for different instances of your application and provide them with different sets of functions for activation or, indeed, different implementations of the same function. If you configured the application to use this technique, the only thing needed for different instances is a single configuration file.
Vic smith
source share