Spring Bean的5种作用域--主要是org.springframework.web.context.request.RequestContextListener
来源:互联网 发布:编导网络课程 编辑:程序博客网 时间:2024/04/27 19:45
org.springframework.web.context.request.RequestContextListener 主要作用是 如果bean想使用作用域为reuqest的时候需要必须配置的,具体详细内容下面已经有了
Spring Bean的5种作用域
singleton作用域:
Spring的scope的默认值是singleton
Spring 只会为每一个bean创建一个实例,并保持bean的引用.
<bean id="bean的id" class="bean的包名.类名" cope="singleton"/> 或
<bean id="bean的id" class="bean的包名.类名" singleton="true"/>
Spring1以上提供
prototype作用域:
每一次请求(将其注入到另一个bean中,或执行getBean()方法)都会产生一个新的bean实例,相当于new操作.
Spring一旦将Bean实例交给(注入)调用者,就不再持有这个bean的引用。就无法再执行bean定义的destroy-method.
清除prototype作用域的bean对象并释放资源,是调用者的职责。
<bean id="bean的id" class="bean的包名.类名" cope="prototype"/> 或
<beanid="bean的id" class="bean的包名.类名" singleton="false"/>
Spring1以上提供
request作用域:
表示该针对每一次HTTP请求都会产生一个新的bean,仅适用于WebApplicationContext环境。
<bean id="bean的id" class="bean的包名.类名" scope="request"/>
Spring1以上提供
session作用域:
表示该针对每一次HTTP请求都会产生一个新的bean,仅适用于WebApplicationContext环境。
<bean id="bean的id" class="bean的包名.类名" scope="session"/>
Spring1以上提供
globalSession作用域:
它仅仅在基于portlet的web应用中才有意义。Portlet规范定义了全局Session的概念,它被所有构成某个portlet web应用的各种不同的portlet所共享。在global session作用域中定义的bean被限定于全局portlet Session的生命周期范围内。如果你在web中使用global session作用域来标识bean,那么,web会自动当成session类型来使用。
<bean id="bean的id" class="bean的包名.类名" scope="globalSession"/>
Spring1以上提供
Web环境作用域的特殊配置:
使用request作用域、request作用域、globalSession作用域还需要进行额外的配置
在低版本的Web容器中(Servlet2.3以前),需要使用过滤器进行配置
- <web-app>
- ...
- <filter>
- <filter-name>requestContextFilter</filter-name>
- <filter-class>org.springframework.web.filter.RequestContextFilter</filter-class> </filter>
- <filter-mapping>
- <filter-name>requestContextFilter</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- ...
- </web-app>
在高版本的Web容器中,可以使用监听器进行配置
- <web-app>
- ...
- <listener>
- <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
- </listener>
- ...
- </web-app>
混合使用作用域的问题:
a Bean是Request作用域,它要被一个singleton作用域的b Bean使用(被注入)。还要使用<aop:sclped-proxy/>配置。
<beans xmlns="..."
...
xmlns:aop="....." 要引入aop命名空间
>
<bean id="a" class="A" scope="request">
<aop:sclped-proxy/>
</bean>
<bean id="b" class="B" scope="singleton">
<property name="a" ref="a"/>
</bean>
- Spring Bean的5种作用域--主要是org.springframework.web.context.request.RequestContextListener
- Spring的作用域RequestContextListener--org.springframework.web.context.request.RequestContextListener 的作用
- org.springframework.web.context.request.RequestContextListener作用
- org.springframework.web.context.request.RequestContextListener作用
- org.springframework.web.context.request.RequestContextListener
- org.springframework.web.context.request.RequestContextListener
- org.springframework.web.context.request.RequestContextListener
- java.lang.ClassNotFoundException: org.springframework.web.context.request.RequestContextListener
- java.lang.ClassNotFoundException: org.springframework.web.context.request.RequestContextListener
- java.lang.ClassNotFoundException: org.springframework.web.context.request.RequestContextListener
- Spring初始化:org.springframework.web.context.ContextLoaderListener的作用
- org.springframework.web.context.ContextLoaderListener的作用
- WebApplicationContext : org.springframework.web.context.ContextLoaderListener的作用
- WebApplicationContext : org.springframework.web.context.ContextLoaderListener作用
- WebApplicationContext : org.springframework.web.context.ContextLoaderListener作用
- WebApplicationContext : org.springframework.web.context.ContextLoaderListener作用
- WebApplicationContext : org.springframework.web.context.ContextLoaderListener作用
- WebApplicationContext : org.springframework.web.context.ContextLoaderListener作用
- php自定义函数call_user_func和call_user_func_array详解
- 暑期个人赛--第三场--A
- LeetCode——Flatten Binary Tree to Linked List
- Java路径问题最终解决方案
- 树莓派的GPIO
- Spring Bean的5种作用域--主要是org.springframework.web.context.request.RequestContextListener
- c++ 中的const 成员函数
- 你会分配30变量!
- java 压缩图片 两种方法
- POJ 2580 Y2K Accounting Bug 贪心
- ev.c
- Java线程(四):线程中断、线程让步、线程睡眠、线程合并
- 浅入浅出触发器
- python 进阶学习之6