posts - 4,  comments - 2,  trackbacks - 0
          初始化web配置
          如果你使用的是Servlet2.4 及以上的web容器,那么僅需要在web.xml 中增加ContextListener即可

          <web-app>
          ...
          <listener>
          ?? ?<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
          </listener>
          ...
          </web-app>


          如果你使用的是早期版本web容器 Servlet 2.4 以前,那么需要使用一個(gè)javax.servlet.Filter 的實(shí)現(xiàn)

          <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>

          ----------------------------------------------------------------------
          RequestContextListener and RequestContextFilter 兩個(gè)類做的都是同樣的工作;將HTTP request 對(duì)象綁定到為該請(qǐng)求提供服務(wù)的Thread。這使具有request or session 作用域的bean能夠在后面的調(diào)用鏈中被訪問到。


          作用域bean 與依賴
          如果打算將一個(gè)Http request 范圍的bean 注入到別一個(gè)bean 中,那么需要注入一個(gè)AOP代理來替代被注入的作用域bean,也就是說需要注入一個(gè)代理對(duì)象。
          注意
          <aop:scoped-proxy/>不能和作用域?yàn)閟ingleton 或 prototype 的bean一起使用。

          <?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-2.0.xsd
          http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
          <!-- a HTTP Session-scoped bean exposed as a proxy -->
          <bean id="userPreferences" class="com.foo.UserPreferences" scope="session">
          <!-- this next element effects the proxying of 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>




          初始化回調(diào)

          可以在Bean 定義中指定一個(gè)普通的初始化方法,即在XML配置文件中通過指定init-method 屬性來完成。

          <bean id="exampleInitBean" class="examples.ExampleBean" init-method="init" />

          public class ExampleBean {
          ?? ?public void init(){
          ?? ??? ?//do some initialization work
          ?? ?}
          }


          析構(gòu)回調(diào)
          <bean id="exampleInitBean" class="examples.ExampleBean" destory-method="cleanup"/>

          public class ExampleBean {
          ?? ?public void cleanup(){
          ?? ??? ?//do some destruction work..
          ?? ?}
          }


          posted on 2006-12-26 13:35 ziwolf 閱讀(371) 評(píng)論(0)  編輯  收藏

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 高淳县| 汉沽区| 巩义市| 东兴市| 临高县| 青田县| 拉萨市| 阿拉善左旗| 富裕县| 泸溪县| 大理市| 宿迁市| 铅山县| 基隆市| 额济纳旗| 柞水县| 堆龙德庆县| 济宁市| 定边县| 文山县| 革吉县| 叙永县| 邹平县| 白城市| 虹口区| 博湖县| 乌拉特后旗| 广水市| 吉林省| 武强县| 息烽县| 登封市| 花莲县| 葵青区| 青州市| 固原市| 抚顺县| 泽普县| 望都县| 英德市| 开平市|