Loading multiple spring config files using ClassPathXmlApplicationContext

I am one of the eclipse fans, in other words, who don’t run applications with command prompt or console with explicit PATH and CLASSPATH 🙂 But there comes a situation, I need to run manually some class files that uses spring beans for some upgrading purpose.

Loading a application context file is what I done, safely ignoring the other parts when I looked into Spring.

ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(“classpath:spring-common-dao.xml”);

will do for that. But as any other web app, I broke the files into pieces as per modules. So, here comes the method that will load all your config files.

ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String []{“classpath:spring-common-dao.xml”,
“classpath:spring-common-service.xml”,”classpath:spring-license-dao.xml”,”classpath:spring-license-view.xml”,
“classpath:spring-license-service.xml”,”classpath:spring-license-schedule.xml”});

Then go with your own way of invoking the beans!

ILicenseService licenseService = (ILicenseService) context.getBean(“licenseService”);

Have a nice day!

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s