国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - 淺談Spring學習之request,session與globalSession作用域

淺談Spring學習之request,session與globalSession作用域

2021-01-09 13:55熟男的博客 Java教程

這篇文章主要介紹了Spring學習之request,session與globalSession作用域的相關內(nèi)容,需要的朋友可以參考下。

與web容器有關的作用域,首先要在Web容器里進行一些配置。

?
1
2
3
4
5
6
7
8
9
<web-app>
  ...
  <listener>
    <listener-class>
      org.springframework.web.context.request.RequestContextListener
    </listener-class>
  </listener>
  ...
</web-app>

Request作用域

考慮下面bean定義:

<bean id="loginAction" class="com.foo.LoginAction" scope="request"/>

針對每次HTTP請求,Spring容器會根據(jù)loginAction bean定義創(chuàng)建一個全新的LoginAction bean實例, 且該loginAction bean實例僅在當前HTTP request內(nèi)有效,因此可以根據(jù)需要放心的更改所建實例的內(nèi)部狀態(tài), 而其他請求中根據(jù)loginAction bean定義創(chuàng)建的實例,將不會看到這些特定于某個請求的狀態(tài)變化。 當處理請求結(jié)束,request作用域的bean實例將被銷毀。

Session作用域

考慮下面bean定義:

<bean id="userPreferences" class="com.foo.UserPreferences" scope="session"/>

針對某個HTTP Session,Spring容器會根據(jù)userPreferences bean定義創(chuàng)建一個全新的userPreferences bean實例, 且該userPreferences bean僅在當前HTTP Session內(nèi)有效。 與request作用域一樣,你可以根據(jù)需要放心的更改所創(chuàng)建實例的內(nèi)部狀態(tài),而別的HTTP Session中根據(jù)userPreferences創(chuàng)建的實例, 將不會看到這些特定于某個HTTP Session的狀態(tài)變化。 當HTTP Session最終被廢棄的時候,在該HTTP Session作用域內(nèi)的bean也會被廢棄掉。

global session作用域

考慮下面bean定義:

<bean id="userPreferences" class="com.foo.UserPreferences" scope="globalSession"/>

global session作用域類似于標準的HTTP Session作用域,不過它僅僅在基于portlet的web應用中才有意義。Portlet規(guī)范定義了全局Session的概念,它被所有構(gòu)成某個portlet web應用的各種不同的portlet所共享。在global session作用域中定義的bean被限定于全局portlet Session的生命周期范圍內(nèi)。

請注意,假如你在編寫一個標準的基于Servlet的web應用,并且定義了一個或多個具有global session作用域的bean,系統(tǒng)會使用標準的HTTP Session作用域,并且不會引起任何錯誤。

作用域依賴問題

If you want to inject (for example) an HTTP request scoped bean into another bean of a longer-lived scope, you may choose to inject an AOP proxy in place of the scoped bean. That is, you need to inject a proxy object that exposes the same public interface as the scoped object but that can also retrieve the real target object from the relevant scope (such as an HTTP request) and delegate method calls onto the real object.

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:aop="http://www.springframework.org/schema/aop"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop.xsd">
 
  <!-- an HTTP Session-scoped bean exposed as a proxy -->
  <bean id="userPreferences" class="com.foo.UserPreferences" scope="session">
    <!-- instructs the container to proxy the surrounding bean -->
    <aop:scoped-proxy/>
  </bean>
 
  <!-- a singleton-scoped bean injected with a proxy to the above bean -->
  <bean id="userService" class="com.foo.SimpleUserService">
    <!-- a reference to the proxied userPreferences bean -->
    <property name="userPreferences" ref="userPreferences"/>
  </bean>
</beans>

總結(jié)

以上就是本文關于Spring學習之request,session與globalSession作用域的全部內(nèi)容,希望對大家有所幫助。感謝大家對本站的支持!

原文鏈接:http://blog.csdn.net/qq_33665647/article/details/53212226

延伸 · 閱讀

精彩推薦
Weibo Article 1 Weibo Article 2 Weibo Article 3 Weibo Article 4 Weibo Article 5 Weibo Article 6 Weibo Article 7 Weibo Article 8 Weibo Article 9 Weibo Article 10 Weibo Article 11 Weibo Article 12 Weibo Article 13 Weibo Article 14 Weibo Article 15 Weibo Article 16 Weibo Article 17 Weibo Article 18 Weibo Article 19 Weibo Article 20 Weibo Article 21 Weibo Article 22 Weibo Article 23 Weibo Article 24 Weibo Article 25 Weibo Article 26 Weibo Article 27 Weibo Article 28 Weibo Article 29 Weibo Article 30 Weibo Article 31 Weibo Article 32 Weibo Article 33 Weibo Article 34 Weibo Article 35 Weibo Article 36 Weibo Article 37 Weibo Article 38 Weibo Article 39 Weibo Article 40
主站蜘蛛池模板: 乳首在线| 欧美日韩免费 | 国产免费啪 | 在线免费观看毛片 | 欧美视频在线播放 | 欧美香蕉| 精品久久久久香蕉网 | 国产精品二区三区 | 99久久精品免费看国产一区二区三区 | 九九热精品在线 | 国产黄视频在线观看 | 国产精品视频一区二区三区四 | 97av在线 | 91国自产精品中文字幕亚洲 | 偷拍一区二区 | 欧美日韩精品在线 | 在线免费黄色 | 欧美日韩成人 | porn亚洲| 色女网| 黄色毛片一级 | 天天操天天干天天 | 久久精品久久综合 | 在线观看一区二区三区四区 | 国产综合视频在线观看 | 精品国产一区二区三区日日嗨 | 日韩成人在线视频 | 日本www视频| 亚洲精品成人av久久 | 91精品电影 | 美女主播精品视频一二三四 | 欧美日韩亚洲一区二区 | 99精品视频在线 | 午夜在线 | 成人午夜| 精品久久精品 | 欧美黄色网页 | 国产一区二区视频在线观看 | 依人成人网 | 成人小视频在线观看 | 欧洲精品久久久久毛片完整版 |