Spring Bean的域scop
来源:互联网 发布:跟淘宝一样的购物软件 编辑:程序博客网 时间:2024/06/06 04:46
1. Spring Bean内置的域scope:
- singleton
- prototype
- request
只能在WebApplicationContext上下文中配置,如XmlWebApplicationContext
- session
只能在WebApplicationContext上下文中配置,如XmlWebApplicationContext
- global session
只能在WebApplicationContext上下文中配置,如XmlWebApplicationContext
- applicatiohn
只能在WebApplicationContext上下文中配置,如XmlWebApplicationContext
2. 为支持Spring Bean的request/session/global session/application域,需要对Web应用的上下文中(在web.xml文件中)进行如下配置:
- 如果已经配置了Spring Web MVC的DispatcherServlet或DispatcherPortlet,则无需再做其他配置
- 如果没有使用Spring Web MVC,需要在web.xml中配置如下:
<listener> <listener-class> org.springframework.web.context.request.RequestContextListener </listener-class> </listener>
- 如果没有使用Spring Web MVC,对于Servlet 3.0以上容器,还可以编程实现org.springframework.web.WebApplicationInitializer接口如下:
public class MyWebAppInitializer implements WebApplicationInitializer { @Override public void onStartup(ServletContext container) { XmlWebApplicationContext appContext = new XmlWebApplicationContext(); appContext.setConfigLocation("/WEB-INF/spring/dispatcher-config.xml"); ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(appContext)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/"); } }
1 0
- Spring Bean的域scop
- Spring中bean的scop
- spring batch 3.0 scop job 问题记录
- spring bean的作用域
- spring bean的作用域
- Spring---->Bean的作用域
- spring bean的作用域
- spring bean的作用域
- spring bean 的作用域
- spring bean的作用域
- Spring Bean的作用域
- Spring Bean的作用域
- Spring Bean的作用域
- Spring bean的作用域
- spring bean的作用域
- spring bean的作用域
- Spring---->Bean的作用域
- Spring、Bean 的作用域
- LeetCode 128. Longest Consecutive Sequence
- Dijkstra找最短路径
- 深入理解RunLoop
- Uva160——Factors and Factorials
- gym 100935B (字典树)
- Spring Bean的域scop
- HTML中img路径问题
- 虚幻4目录结构
- JAVA代码实现FTP文件下载
- GitHub 上排名前 100 的 Objective-C 项目简介
- 237. Delete Node in a Linked List
- 1008-I
- C++多线程(一)
- [BZOJ1593][Usaco2008 Feb]Hotel 旅馆(线段树)