Spring Framework中applicationContext.xml和spring-servlet.xml之间的区别 [英] Difference between applicationContext.xml and spring-servlet.xml in Spring Framework

查看:99
本文介绍了Spring Framework中applicationContext.xml和spring-servlet.xml之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  • 无论如何在Spring中 applicationContext.xml spring-servlet.xml 相关框架?

  • applicationContext.xml 中声明的属性文件是否可用于 DispatcherServlet

  • 在相关说明中,为什么我需要 * - servlet.xml 在所有?为什么 applicationContext.xml 单独不足?

  • 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.xml alone insufficient?

推荐答案

Spring允许您在父子层次结构中定义多个上下文。

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

applicationContext.xml 定义root webapp context的bean,即与webapp关联的上下文。

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

spring-servlet.xml (或者你称之为的其他任何东西)定义了一个servlet应用程序上下文的bean。在webapp中可以有很多这样的,每个Spring servlet一个(例如 spring1-servlet.xml for servlet spring1 spring2-servlet.xml for servlet spring2 )。

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.xml for servlet spring1, spring2-servlet.xml for servlet spring2).

中的bean spring-servlet.xml 可以引用 applicationContext.xml 中的bean,但反之亦然。

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

所有Spring MVC控制器必须进入 spring-servlet.xml 上下文。

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

在大多数情况下, applicationContext.xml 上下文是不必要的。它通常用于包含在webapp中的所有servlet之间共享的bean。如果你只有一个servlet,那么除非你有特定用途,否则没什么意义。

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.

这篇关于Spring Framework中applicationContext.xml和spring-servlet.xml之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆