Can we change the location of springBeanConfiguration file in spring mvc?

220 views Asked by At

I have developed a Spring MVC web application. In this application I have two containers and the location of the spring bean configuration file is:

/WEB-INF/dispatcher-servlet.xml 

I have changed the name of the spring bean cfg file but I also want to change the location to:

/com/nt/cfg/applicationContext.xml 

However, Spring is not recognizing any location other than /WEB-INF/

2

There are 2 answers

1
gonzaloan On

You just need to declare de route when you create the ClassPathXmlApplicationContext:

ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");

The default location is the resources folder.

Hope this help you.

1
Alien On

The answer is YES, you can change the name and location of the configuration file but you have to make spring aware of the new name and location.

ApplicationContext context = new ClassPathXmlApplicationContext("context.xml");    

It will load the context from context.xml file (context.xml should be present in classpath).
You can create new Applicationcontext by passing desired XML file as parameter to constructor.

So after changing name and location of the file you have to register here for spring reference so that spring can find the configuration file.