zoukankan      html  css  js  c++  java
  • spring配置文件和spring mvc配置文件的区别

    Question:

    • Are applicationContext.xml and spring-servlet.xml related anyhow in Spring Framework?
    • Will the properties files declared in applicationContext.xml be available to DispatcherServlet?
    • On a related note, why do I need a *-servlet.xml at all? Why is applicationContext.xmlalone insufficient?

    Answer:

    Spring lets you define multiple contexts in a parent-child hierarchy.

    The applicationContext.xml defines the beans for the "root webapp context", i.e. the context associated with the webapp.

    The spring-servlet.xml (or whatever else you call it) defines the beans for one servlet's app context. There can be many of these in a webapp, one per Spring servlet (e.g. spring1-servlet.xmlfor servlet spring1spring2-servlet.xml for servlet spring2).

    Beans in spring-servlet.xml can reference beans in applicationContext.xml, but not vice versa.

    All Spring MVC controllers must go in the spring-servlet.xml context.

    In most simple cases, the applicationContext.xml context is unnecessary. It is generally used to contain beans that are shared between all servlets in a webapp. If you only have one servlet, then there's not really much point, unless you have a specific use for it.

  • 相关阅读:
    C++格式化输入输出
    算法的时间复杂度和空间复杂度
    C++编程中const和#define的区别
    C#中结构体和类的区别
    SQL之删除触发器
    Windows添加和取消右键管理员权限
    SQL之trigger(触发器)
    SQL VIEW(视图)
    二分查找的实现
    C++中this指针
  • 原文地址:https://www.cnblogs.com/zhouj-happy/p/6088891.html
Copyright © 2011-2022 走看看