I have a need to change the spring applicationContext.xml file that is used based upon a property, this property MUST be defined somewhere outside of the war file (ie. it can’t be in web.xml). Currently, I’ve arrived at the following solution (see my answer below), wondering if there’s a better way to do this?
I have a need to change the spring applicationContext.xml file that is used based
Share
Have you considered using the beanRefContext approach. (ContextSingletonBeanFactoryLocator). This way you can configure your spring config files (and their names) via another spring config file.
Then you can paramaterise that file by whatever means you deem appropriate and switch the file names that way.
The file looks like this:
And you can use PropertyPlaceHolderConfigurer to set the value of NameOfBeanConfigFile.
I like this approach as it means I can mix static bean config file names with dynamic bean config file names and thus don’t have to duplicate bean config.
When I had to do a similar thing I would parameterise via a config file loaded as a URL resource (via jndi)