锘??xml version="1.0" encoding="utf-8" standalone="yes"?>免费av网站大全久久,亚洲精品3区,亚洲看片免费http://www.aygfsteel.com/cyantide/category/36408.htmlzh-cnFri, 25 Sep 2009 11:45:08 GMTFri, 25 Sep 2009 11:45:08 GMT60Spring Bean浣滅敤鍩熶粙緇?杞笘)http://www.aygfsteel.com/cyantide/archive/2009/09/14/294980.html寰瑧娌欐紶寰瑧娌欐紶Mon, 14 Sep 2009 02:30:00 GMThttp://www.aygfsteel.com/cyantide/archive/2009/09/14/294980.htmlhttp://www.aygfsteel.com/cyantide/comments/294980.htmlhttp://www.aygfsteel.com/cyantide/archive/2009/09/14/294980.html#Feedback0http://www.aygfsteel.com/cyantide/comments/commentRss/294980.htmlhttp://www.aygfsteel.com/cyantide/services/trackbacks/294980.html
singleton錛歋pringIoc瀹瑰櫒鍙細鍒涘緩璇ean鐨勫敮涓瀹炰緥錛屾墍鏈夌殑璇鋒眰鍜屽紩鐢ㄩ兘鍙嬌鐢ㄨ繖涓疄渚?
Property:  姣忔璇鋒眰閮藉垱寤轟竴涓疄渚?
request:    鍦ㄤ竴嬈ttp璇鋒眰涓紝瀹瑰櫒浼氳繑鍥炶Bean鐨勫悓涓涓疄渚嬶紝鑰屽浜庝笉鍚岀殑鐢ㄦ埛璇鋒眰錛屼細榪斿洖涓嶅悓鐨勫疄渚嬨傞渶瑕佹敞鎰忕殑鏄紝璇ヤ綔鐢ㄥ煙浠呭湪鍩轟簬Web鐨? Spring ApplicationContext鎯呭艦涓嬫湁鏁堬紝浠ヤ笅鐨剆ession鍜実lobal Session涔熸槸濡傛
session錛氬悓涓婏紝鍞竴鐨勫尯鍒槸璇鋒眰鐨勪綔鐢ㄥ煙鍙樹負浜唖ession
global session錛氬叏灞鐨凥ttpSession涓紝瀹瑰櫒浼氳繑鍥炶bean鐨勫悓涓涓疄渚嬶紝鍏稿瀷涓哄湪鏄嬌鐢╬ortlet context鐨勬椂鍊欐湁鏁堬紙榪欎釜姒傚康鏈漢涔熶笉鎳傦級

娉ㄦ剰錛氬鏋滆鐢ㄥ埌request錛宻ession錛実lobal session鏃墮渶瑕侀厤緗?

servlet2.4鍙婁互涓婏細
鍦╳eb.xml涓坊鍔狅細
<listener>
    <listener-class>org.springframework.web.context.scope.RequestContextListener />
</listener>

servlet2.4浠ヤ笅錛?
闇瑕侀厤緗竴涓繃婊ゅ櫒
<filter>
    <filter-name>XXXX</filter-name>
    <filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
<filter-mapping>
    <filter-name>XXXX</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

鍙﹀錛屼粠2.0寮濮嬶紝鍙互鑷繁瀹氫箟浣滅敤鍩燂紝浣嗛渶瑕佸疄鐜皊cope錛屽茍閲嶅啓get鍜宺emove鏂規硶

鐗瑰埆瑕佸紩璧鋒敞鎰忕殑鏄細
   涓鑸儏鍐典笅鍓嶉潰涓ょ浣滅敤鍩熸槸澶熺敤鐨勶紝浣嗗鏋滄湁榪欐牱涓縐嶆儏鍐碉細singleton綾誨瀷鐨刡ean寮曠敤涓涓猵rototype鐨刡ean鏃朵細鍑虹幇闂錛屽洜涓? singleton鍙垵濮嬪寲涓嬈★紝浣唒rototype姣忚姹備竴嬈¢兘浼氭湁涓涓柊鐨勫璞★紝浣唒rototype綾誨瀷鐨刡ean鏄痵ingleton綾誨瀷 bean鐨勪竴涓睘鎬э紝鐞嗘墍褰撶劧涓嶅彲鑳芥湁鏂皃rototpye鐨刡ean浜х敓錛屼笌鎴戜滑鐨勮姹備笉絎?

瑙e喅鏂規硶錛?
1.鏀懼純Ioc錛岃繖涓庤璁″垵琛蜂笉絎︼紝騫朵唬鐮侀棿浼氭湁鑰﹀悎
2錛孡ookup鏂規硶娉ㄥ叆錛屾帹鑽?

浣嗗湪鐢↙ookup鏂規硶娉ㄥ叆鏃朵篃闇瑕佹敞鎰忎竴鐐癸細闇瑕佸湪寮曠敤鐨凚ean涓畾涓涓竴涓娊璞″湴榪斿洖琚紩鐢ㄥ璞$殑鏂規硶

package com.huyong.lookup;

import java.util.Calendar;

/**
* @author HuYong Email:yate7571@hotmail.com
*/
public class CurrentTime {
private Calendar now = Calendar.getInstance();

public void printCurrentTime() {
System.out.println("Current Time:" + now.getTime());
}

}


package com.huyong.lookup;

/**
* @author HuYong Email:yate7571@hotmail.com
*/
public abstract class LookupBean {
private CurrentTime currentTime;

public CurrentTime getCurrentTime() {
return currentTime;
}

public void setCurrentTime(CurrentTime currentTime) {
this.currentTime = currentTime;

}
public abstract CurrentTime createCurrentTime();

}

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

<bean id="currentTime" class="com.huyong.lookup.CurrentTime"
scope="prototype">
</bean>
<bean id="lookupBean" class="com.huyong.lookup.LookupBean"
scope="singleton">
<lookup-method name="createCurrentTime" bean="currentTime" />
<property name="currentTime" ref="currentTime"></property>
</bean>

</beans>


Main Test錛?
package com.huyong.lookup;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;

/**
* @author HuYong Email:yate7571@hotmail.com
*/
public class LookupMain {

/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
ClassPathResource resource = new ClassPathResource(
"applicationContext.xml");
BeanFactory factory = new XmlBeanFactory(resource);

LookupBean lookupBean = (LookupBean) factory.getBean("lookupBean");
System.out.println("----------first time---------");
System.out.println("getCurrentTime:");
lookupBean.getCurrentTime().printCurrentTime();
System.out.println("createCurrentTime:");
lookupBean.createCurrentTime().printCurrentTime();

Thread.sleep(12345);

System.out.println("---------second time---------");
System.out.println("getCurrentTime:");
LookupBean lookupBean02 = (LookupBean) factory.getBean("lookupBean");
lookupBean02.getCurrentTime().printCurrentTime();
System.out.println("createCurrentTime:");
lookupBean02.createCurrentTime().printCurrentTime();

}

}

]]>
jsp涓嬌鐢╯pring aop (杞笘)http://www.aygfsteel.com/cyantide/archive/2008/08/05/220114.html寰瑧娌欐紶寰瑧娌欐紶Tue, 05 Aug 2008 03:11:00 GMThttp://www.aygfsteel.com/cyantide/archive/2008/08/05/220114.htmlhttp://www.aygfsteel.com/cyantide/comments/220114.htmlhttp://www.aygfsteel.com/cyantide/archive/2008/08/05/220114.html#Feedback0http://www.aygfsteel.com/cyantide/comments/commentRss/220114.htmlhttp://www.aygfsteel.com/cyantide/services/trackbacks/220114.html鍦↗SP涓嬌鐢⊿pring鍏跺疄寰堝鏄擄紝涓昏鐢ㄥ埌Spring鐨刉ebApplicationContextUtils.getWebApplicationContext鍑芥暟銆?/p>

瑕佸啀JSP閲岄潰寰楀埌ApplicationContext闇瑕佽繖涔堝仛錛岄鍏坕mport="org.springframework.web.context.support.*,org.springframework.context.*"

鐒跺悗鍙互閫氳繃濡備綍鍋氭硶錛?/p>

ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());

榪欐牱灝卞緱鍒頒簡ApplicationContext錛屽氨鍙互鎿嶄綔Spring浜嗐?/p>

JSP鏈潵灝卞彲浠ヨ涓烘槸涓涓猄ervlet錛屾墍浠ヤ嬌鐢╣etServletContext()灝辨槸鐞嗘墍搴斿綋浜嗐?/p>

涓錛歸eb.xml閰嶇疆

<servlet>
<servlet-name>context</servlet-name>
<servlet-class>
org.springframework.web.context.ContextLoaderServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>

 


浜岋細鍦↗SP

<%@ page import="org.springframework.context.ApplicationContext"%>
<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@ page import="com.yourcompany.service.CategoryService"%>

<%
//涓婇潰鐨凜ategoryService寮曠敤鏄垜鑷繁鐨勪笢瑗?br /> //applicationContext.xml涓竴瀹氳鏈夊畬鏁寸殑渚濊禆閾撅紝浠巇ataSource鍒癈ategoryService

ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());
CategoryService cs = (CategoryService) ctx.getBean("CategoryService");
List list =cs.getCategoryDAO().findAll();
%>



]]>
主站蜘蛛池模板: 长沙市| 左贡县| 稷山县| 高淳县| 新营市| 福州市| 平凉市| 和静县| 黔南| 长武县| 嵩明县| 云阳县| 原阳县| 慈溪市| 湘西| 钟祥市| 金华市| 莫力| 桃源县| 博爱县| 岚皋县| 阿荣旗| 铜鼓县| 宁晋县| 宜城市| 宝坻区| 信丰县| 水城县| 巴林右旗| 桑日县| 乌什县| 太谷县| 大田县| 桦甸市| 克山县| 临沭县| 巩义市| 萍乡市| 东台市| 英吉沙县| 扶绥县|