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.

  • 相关阅读:
    Tomcat安装和配置过程
    Java集合框架概述
    Hash表的原理
    Java 浅拷贝和深拷贝的理解和实现方式
    Nginx 配置上传文件大小
    将博客搬至CSDN
    vscode中设置vue代码片段
    底部标签栏获取token失败
    Eacharts K线报错问题
    阿里字体图标库在项目中引用
  • 原文地址:https://www.cnblogs.com/zhouj-happy/p/6088891.html
Copyright © 2011-2022 走看看