
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference Between ApplicationContext.xml and Spring-servlet.xml in Spring Framework
Applicationcontext.xml - It is standard spring context file which contains all beans and the configuration that are common among all the servlets. It is optional file in case of web app. Spring uses ContextLoaderListener to load this file in case of web application.
Spring-servlet.xml- It is a single entry point for Spring. DispatcherServlet scan this file and starts to load its component. It defines the bean and configuration that are only related to that servlet.
In Spring MVC application we chain them in below order −
web.xml --> dispatcher servlet --> application context
Sr. No. | Key | ApplicationContext.xml | Spring-servlet.xml |
---|---|---|---|
1 |
Basic |
applicationContext.xml defines the beans that are shared among all the servlets. If your application has more than one servlet, then defining the common resources in the applicationContext.xml would make more sense. |
spring-servlet.xml defines the beans that are related only to that servlet. Here it is the dispatcher servlet. So, your Spring MVC controllers must be defined in this file. |
2 |
Scanning |
We can add filter for package excluding controller package |
In spring-servlet.xml we include component scan for Controller package. |
3 |
References |
Beans in ApplicationContext.xml can have reference beans in spring-servlet.xml |
Beans in spring-servlet.xml can reference beans in applicationContext.xml |
Advertisements