锘??xml version="1.0" encoding="utf-8" standalone="yes"?>日韩视频在线观看国产,成人激情综合,国产高清精品一区http://www.aygfsteel.com/xiaosao/category/19242.html涓嶆噦鎴戠殑浜?, 紱諱笉浜嗘垜 , 璇ヤ簡瑙d簡瑙f垜 !鑰屾噦鎴戠殑浜?, 鏇寸涓嶄簡鎴?, 鍥犱負浠栦滑鐖辨垜 銆?/description>zh-cnTue, 27 Feb 2007 12:30:36 GMTTue, 27 Feb 2007 12:30:36 GMT60DataSource娉ㄥ叆http://www.aygfsteel.com/xiaosao/articles/94023.htmlcAng^ErcAng^ErMon, 15 Jan 2007 12:03:00 GMThttp://www.aygfsteel.com/xiaosao/articles/94023.htmlhttp://www.aygfsteel.com/xiaosao/comments/94023.htmlhttp://www.aygfsteel.com/xiaosao/articles/94023.html#Feedback0http://www.aygfsteel.com/xiaosao/comments/commentRss/94023.htmlhttp://www.aygfsteel.com/xiaosao/services/trackbacks/94023.html http://www.is.pku.edu.cn/blog/?date=2004-12-29&id=2&m=display

DataSource娉ㄥ叆


xinyua

caterpillar 灝嶆柤涓嶅悓鐨勮硣鏂欏韓瀛樺彇闇姹傦紝鎴戝戜嬌鐢↗DBC渚嗚В姹洪欏嬪晱欏岋紝灝嶆柤涓嶅悓鐨勮硣鏂欓f帴渚嗘簮闇姹傦紝Spring鍓囨彁渚涗簡DataSource娉ㄥ叆錛屾洿鎻涜硣鏂欎締婧愬彧瑕佸湪Bean瀹氱京妾斾腑淇敼閰嶇疆錛岃屼笉鐢ㄤ慨鏀逛換浣曚竴琛岀▼寮忋?鍥犳噳涓嶅悓鐨勭郴緄憋紝鎳夌敤紼嬪紡鍙兘浣跨敤涓嶅悓鐨勮硣鏂欎締婧愶紝浣嗗绱旂斗鐨勪嬌鐢↗DBC銆侀忛亷閫f帴姹犮佹垨鏄忛亷JNDI絳夌瓑錛岃硣鏂欎締婧愮殑鏇村嫊鏄簳灞ょ殑琛岀偤錛屼笉鎳夊獎闊垮埌涓婂堡鐨勬キ鍕欓倧杓紝鐐烘錛屾偍鍙互鍦ㄩ渶瑕佸彇寰楅f帴渚嗘簮鐨凚ean涓婁繚鐣欎竴鍊嬭硣鏂欎締婧愭敞鍏ョ殑浠嬮潰錛岃畵渚濊炒鐨勮硣鏂欎締婧愮敱瑭蹭粙闈㈡敞鍏?br />灝嶆柤涓嶅悓鐨勮硣鏂欏韓瀛樺彇闇姹傦紝鎴戝戜嬌鐢↗DBC渚嗚В姹洪欏嬪晱欏岋紝灝嶆柤涓嶅悓鐨勮硣鏂欓f帴渚嗘簮闇姹傦紝Spring鍓囨彁渚涗簡DataSource娉ㄥ叆錛屾洿鎻涜硣鏂欎締婧愬彧瑕佸湪Bean瀹氱京妾斾腑淇敼閰嶇疆錛岃屼笉鐢ㄤ慨鏀逛換浣曚竴琛岀▼寮忋?

鍥犳噳涓嶅悓鐨勭郴緄憋紝鎳夌敤紼嬪紡鍙兘浣跨敤涓嶅悓鐨勮硣鏂欎締婧愶紝浣嗗绱旂斗鐨勪嬌鐢↗DBC銆侀忛亷閫f帴姹犮佹垨鏄忛亷JNDI絳夌瓑錛岃硣鏂欎締婧愮殑鏇村嫊鏄簳灞ょ殑琛岀偤錛屼笉鎳夊獎闊垮埌涓婂堡鐨勬キ鍕欓倧杓紝鐐烘錛屽彲浠ュ湪闇瑕佸彇寰楅f帴渚嗘簮鐨凚ean涓婁繚鐣欎竴鍊嬭硣鏂欎締婧愭敞鍏ョ殑浠嬮潰錛岃畵渚濊炒鐨勮硣鏂欎締婧愮敱瑭蹭粙闈㈡敞鍏ャ備緥濡傛垜鍊戜締瀵竴鍊嬬啊鍠殑Bean錛?

浠g⒓:
package onlyfun.caterpillar;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽
import javax.sql.DataSource;
import java.sql.Connection;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽
public class DataBean {
聽 聽 private DataSource dataSource;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽
聽 聽 public void setDataSource(DataSource dataSource) {
聽 聽 聽 聽 this.dataSource = dataSource;
聽 聽 }
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽
聽 聽 public void testDataSource() {
聽 聽 聽 聽 try {
聽 聽 聽 聽 聽 聽 Connection connection = dataSource.getConnection();
聽 聽 聽 聽 聽 聽 if(connection != null)
聽 聽 聽 聽 聽 聽 聽 聽 System.out.println("test ok!");
聽 聽 聽 聽 }
聽 聽 聽 聽 catch (Exception e) {
聽 聽 聽 聽 聽 聽 e.printStackTrace();
聽 聽 聽 聽 }
聽 聽 }
}


閫欐槸涓鍊嬬啊鍠殑娓│Spring DataSource娉ㄥ叆鐨勭▼寮忥紝鎴戝戦忛亷javax.sql.DataSource浠嬮潰渚嗘敞鍏ヨ硣鏂欎締婧愶紝Spring鎻愪緵浜唎rg.springframework.jdbc.datasource.DriverManagerDataSource渚嗗彇寰桪ataSource錛屽畠瀵︿綔浜唈avax.sql.DataSource錛屽皣涔嬬暥浣滀竴鍊婤ean錛屼箣寰屽啀娉ㄥ叆DataBean涓嵆鍙紝Bean瀹氱京妾斿彲浠ラ欓杭鎾板錛?
浠g⒓:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN/EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
聽 聽 <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
聽 聽 聽 聽 <property name="driverClassName">
聽 聽 聽 聽 聽 聽 <value>com.mysql.jdbc.Driver</value>
聽 聽 聽 聽 </property>
聽 聽 聽 聽 <property name="url">
聽 聽 聽 聽 聽 聽 <value>jdbc:mysql://localhost:3306/TestDB</value>
聽 聽 聽 聽 </property>
聽 聽 聽 聽 <property name="username">
聽 聽 聽 聽 聽 聽 <value>caterpillar</value>
聽 聽 聽 聽 </property>
聽 聽 聽 聽 <property name="password">
聽 聽 聽 聽 聽 聽 <value>123456</value>
聽 聽 聽 聽 </property>
聽 聽 </bean>
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽
聽 聽 <bean id="dataBean" class="onlyfun.caterpillar.DataBean">
聽 聽 聽 聽 <property name="dataSource">
聽 聽 聽 聽 聽 聽 <ref bean="dataSource"/>
聽 聽 聽 聽 </property>
聽 聽 </bean>
</beans>


濡傛灉涔嬪墠鍙嬌鐢╯pring-core.jar閫欏嬮鍒ュ韓錛岄倓蹇呴爤鍔犲叆spring-dao.jar錛宱rg.springframework.jdbc.datasource.DriverManagerDataSource鏄寘鎷湪閫欏嬮鍒ュ韓涓紝濡傛灉浣跨敤鐨勬槸spring.jar錛岀暥涓凡綞撳寘鎷簡錛岀劇闇鍔犲叆浠諱綍鐨刯ar錛岀暥鐒訛紝鐐轟簡浣跨敤JDBC錛屽繀闋堣鏈塉DBC椹呭嫊紼嬪紡鐨刯ar妾斻?

鍙互鐢ㄤ笅闈㈤欐紼嬪紡綈″柈鐨勬脯瑭︿竴涓嬶細
浠g⒓:
BeanDefinitionRegistry reg = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(reg);
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽
reader.loadBeanDefinitions(new ClassPathResource("bean.xml"));;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽
BeanFactory bf = (BeanFactory) reg;
DataBean dataBean = (DataBean) bf.getBean("dataBean");
dataBean.testDataSource();


DriverManagerDataSource涓︽矑鏈夋彁渚涢f帴姹犵殑鍔熻兘錛屽彧鑳戒綔浣滅啊鍠殑鍠閫f帴娓│錛岀従鍦ㄥ亣璦f帴娓│娌掓湁鍟忛浜嗭紝鎯寵鎻涗笂DBCP浠ョ嵅寰楅f帴姹犵殑鍔熻兘錛屽墖鍘熺▼寮忎笉鐢ㄦ洿鍕曪紝鍙鏀規敼Bean瀹氱京妾斿氨鍙互浜嗭細
浠g⒓:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN/EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
聽 聽 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
聽 聽 聽 聽 <property name="driverClassName">
聽 聽 聽 聽 聽 聽 <value>com.mysql.jdbc.Driver</value>
聽 聽 聽 聽 </property>
聽 聽 聽 聽 <property name="url">
聽 聽 聽 聽 聽 聽 <value>jdbc:mysql://localhost:3306/TestDB</value>
聽 聽 聽 聽 </property>
聽 聽 聽 聽 <property name="username">
聽 聽 聽 聽 聽 聽 <value>caterpillar</value>
聽 聽 聽 聽 </property>
聽 聽 聽 聽 <property name="password">
聽 聽 聽 聽 聽 聽 <value>123456</value>
聽 聽 聽 聽 </property>
聽 聽 </bean>
聽 聽 <bean id="dataBean" class="onlyfun.caterpillar.DataBean">
聽 聽 聽 聽 <property name="dataSource">
聽 聽 聽 聽 聽 聽 <ref bean="dataSource"/>
聽 聽 聽 聽 </property>
聽 聽 </bean>
</beans>


鐝懼湪鎴戝戜嬌鐢ㄧ殑鏄痮rg.apache.commons.dbcp.BasicDataSource浣滅偤娉ㄥ叆鐨凞ataSource婧愶紝鐐轟簡浣跨敤DBCP鐨勫姛鑳斤紝蹇呴爤瑕佸皣commons-dbcp.jar鍔犲叆CLASSPATH涓紝鍙﹀閭勯渶瑕乧ommons-pool.jar鑸嘽ommons-collections.jar錛岄欎簺閮藉彲浠ュ湪Spring鐨勭浉渚濈増鏈腑鐨刲ib鐩寗涓嬫壘鍒般?

娉ㄦ剰鍒版垜鍊戝湪dataSource Bean涓婂鍛婁簡destroy-method錛屽姝ゅ彲浠ョ⒑淇滲eanFactory鍦ㄩ棞闁夋檪涔熶竴浣甸棞闁塀asicDataSource銆?

濡傛灉Servlet瀹瑰櫒鎻愪緵浜咼NDI璩囨枡婧愶紝涔熷彲浠ョ啊鍠殑鎻涗笂閫欏嬭硣鏂欐簮錛?
浠g⒓:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN/EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
聽 聽 <bean id="dataSource" class="org.springframework.indi.JndiObjectFactoryBean">
聽 聽 聽 聽 <property name="jndiName">
聽 聽 聽 聽 聽 聽 <value>jdbc/TestDB</value>
聽 聽 聽 聽 </property>
聽 聽 </bean>
聽 聽 <bean id="dataBean" class="onlyfun.caterpillar.DataBean">
聽 聽 聽 聽 <property name="dataSource">
聽 聽 聽 聽 聽 聽 <ref bean="dataSource"/>
聽 聽 聽 聽 </property>
聽 聽 </bean>
</beans>


鐐轟簡浣跨敤org.springframework.indi.JndiObjectFactoryBean錛屽繀闋堝姞鍏pring-context.jar閫欏嬮鍒ュ韓錛宩ndiName瀵﹂殯涓婅鏍規摎鎵璦畾鐨凧NDI鏌ヨ鍚嶇ū


cAng^Er 2007-01-15 20:03 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 科尔| 观塘区| 海淀区| 岫岩| 涿州市| 隆安县| 汉中市| 都安| 新宾| 安宁市| 邳州市| 南投县| 阳西县| 湖州市| 壶关县| 兴海县| 阿城市| 宜兰县| 独山县| 彰武县| 罗定市| 大名县| 夏邑县| 乌恰县| 大田县| 察雅县| 鄄城县| 蒲江县| 景谷| 襄汾县| 垣曲县| 太仆寺旗| 梁山县| 云梦县| 延吉市| 新河县| 环江| 增城市| 梧州市| 岳西县| 北碚区|