Servlet的Spring根WebApplicationContext [英] Spring root WebApplicationContext for Servlet

查看:47
本文介绍了Servlet的Spring根WebApplicationContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用SpringMVC DispatcherServlet加载WebApplicationContext的Web应用程序.Spring参考文档:

I have a webapp that uses SpringMVC DispatcherServlet to load a WebApplicationContext. The Spring reference documentation says:

"每个DispatcherServlet都有自己的WebApplicationContext,它继承所有已经在根WebApplicationContext .这些继承的bean可以覆盖特定于servlet的范围,您可以定义新的特定于作用域的bean本地到给定的servlet实例.

"each DispatcherServlet has its own WebApplicationContext, which inherits all the beans already defined in the root WebApplicationContext. These inherited beans can be overridden in the servlet-specific scope, and you can define new scope-specific beans local to a given servlet instance.

但是我应该把根WebApplicationContext放在哪里?

But where do I put this root WebApplicationContext?

推荐答案

我们在 WEB-INF 目录中具有 applicationContext.xml ,该配置中的bean是可用于 spring-servlet.xml 配置,其使用

We have applicationContext.xml in theWEB-INF directory, and the beans in that config are available to the spring-servlet.xml config, its defined using

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>

使用负责管理根上下文的 ContextLoaderListener 方式

By the way its the ContextLoaderListener which is responsible for managing the root context

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

这篇关于Servlet的Spring根WebApplicationContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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