Deploy the Spring application, reading from different properties files.

From the good person over at MyThinkPond, here is how I deployed the same WAR file, into the same webapps directory of Tomcat, but had it read from different properties files. The reason for my need to do this was that I wanted the application, depending on its URL (the war file name) to pick up its relevant properties file.

Therefore, I needed the app to be able to know its name.

Just like my buddy over at  MyThinkPond I created the following class with a static method to get my context:

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class ApplicationContextProvider implements ApplicationContextAware{
 private static ApplicationContext ctx = null;
 public static ApplicationContext getApplicationContext() {
return ctx;
 public void setApplicationContext(ApplicationContext ctx) throws BeansException {
this.ctx = ctx;

and in my spring bean configuration xml file I added the following:

 <bean id="applicationContextProvider" class="com.mydomain.myappname.ApplicationContextProvider"></bean>

and then in my classes, I was able to do the following:

ApplicationContext ctx = ApplicationContextProvider.getApplicationContext();


Igor Stepanovs was famous for changing his property files depending on his application name.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: