久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術(shù)文章
文章詳情頁

spring IOC中三種依賴注入方式

瀏覽:129日期:2023-12-02 18:25:16

一、Spring IOC(依賴注入的三種方式):

1、Setter方法注入。

2、構(gòu)造方法注入。

使用構(gòu)造方法,注入bean值。關(guān)鍵代碼:public UserServiceImpl(UserDao dao) {this.dao=dao;} <bean class='service.impl.UserServiceImpl'> <constructor-arg><ref bean='dao'/></constructor-arg> </bean>

3、P命名空間注入。

二、Spring IOC(依賴注入的五種不同數(shù)據(jù)類型):

1、注入直接量(基本數(shù)據(jù)類型、字符串)

2、引用其他Bean組件。(面向接口編程)

ref屬性:

<bean class='dao.impl.UserDaoImpl'></bean><bean class='service.impl.UserServiceImpl'> <property name='dao' ref='dao'></property></bean>

<ref>子元素:

<bean class='dao.impl.UserDaoImpl'></bean><bean class='service.impl.UserServiceImpl'> <property name='dao'> <ref bean='dao'/> </property></bean>

p命名空間:

xmlns:p='http://www.springframework.org/schema/p'<bean class='dao.impl.UserDaoImpl'></bean><bean p:dao-ref='dao'></bean>

3、使用內(nèi)部Bean。

<bean class='service.impl.UserServiceImpl'> <property name='dao'> <bean /> </property> </bean>

4、注入集合類型的屬性。

5、注入null和空字符串。

到此這篇關(guān)于spring IOC中三種依賴注入方式的文章就介紹到這了,更多相關(guān)spring IOC依賴注入內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 遂平县| 兰考县| 平乡县| 贵溪市| 菏泽市| 乐昌市| 民县| 稷山县| 文化| 东方市| 大石桥市| 称多县| 六枝特区| 宣恩县| 都安| 郓城县| 潼南县| 宁河县| 通许县| 论坛| 义乌市| 扶沟县| 高要市| 通辽市| 江阴市| 红安县| 察雅县| 合水县| 中宁县| 嘉黎县| 六枝特区| 渭源县| 九龙坡区| 连平县| 九江市| 河北区| 蓝山县| 东港市| 昌吉市| 龙泉市| 奎屯市|