Difference between applicationContext.xml and spring-servlet.xml in Spring Framework

前端 未结 6 550
挽巷
挽巷 2020-11-22 01:35
  • Are applicationContext.xml and spring-servlet.xml related anyhow in Spring Framework?
  • Will the properties files declared in
6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 02:04

    In simple words,

    applicationContext.xml defines the beans that are shared among all the servlets. If your application have 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.

    There is nothing wrong in defining all the beans in the spring-servlet.xml if you are running only one servlet in your web application.

提交回复
热议问题