最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

spring IOC中三種依賴注入方式

 更新時(shí)間:2021年08月17日 16:22:32   作者:Nirvana8921  
這篇文章主要介紹了spring IOC中三種依賴注入方式,Spring使用注入方式,為什么使用注入方式,這系列問(wèn)題實(shí)際歸結(jié)起來(lái)就是一句話,Spring的注入和IoC(本人關(guān)于IoC的闡述)反轉(zhuǎn)控制是一回事

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

1、Setter方法注入。

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

使用構(gòu)造方法,注入bean值。
關(guān)鍵代碼:
	public UserServiceImpl(UserDao dao) {
		this.dao=dao;
	}
	
    <bean id="service" 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 id="dao" class="dao.impl.UserDaoImpl"></bean>
	<bean id="service" class="service.impl.UserServiceImpl">
	 <property name="dao" ref="dao"></property>
	</bean>

   <ref>子元素:

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

  p命名空間:

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

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

<bean id="service" class="service.impl.UserServiceImpl">
	          <property name="dao">
	                 <bean class="dao.impl.UserDaoImpl"/>
	          </property>
	     </bean>

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

5、注入null和空字符串。

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

相關(guān)文章

最新評(píng)論

吉木乃县| 桑日县| 大兴区| 张北县| 巴里| 克东县| 梧州市| 怀仁县| 花垣县| 盘锦市| 阿勒泰市| 武强县| 荆门市| 湘潭市| 昆明市| 保山市| 区。| 贡山| 阿图什市| 大厂| 临城县| 岢岚县| 宣汉县| 东兴市| 孙吴县| 嫩江县| 墨脱县| 邵阳市| 临沭县| 鲁山县| 安达市| 田东县| 东兰县| 丰县| 荃湾区| 桓台县| 左云县| 金乡县| 大连市| 瑞金市| 台中县|