Spring之創建Bean的三種方式
<!--1.無參構造創建bean,反射,通過setter方法--> <!--默認單例bean工廠;--> <!--動態注入默認根據類型--> <bean id="stu" class="cn.kgc.kb08.spring.entity.Student" autowire="byType" scope="singleton" > <property name="age" value="18"/> <property name="gender" value="女"/> <property name="name" value="張三"/> </bean> <!--2.有參構造創建bean--> <bean id="stu2" class="cn.kgc.kb08.spring.entity.Student"> <constructor-arg index="0" value="Henry"/> <constructor-arg index="1" value="1"/> <constructor-arg index="2" value="Henry"/> </bean> <!--3.通過工廠創建bean--> <!--不能注入參數--> <bean id="stuFactory" class="cn.kgc.kb08.spring.factory.StudentFactory"/> <bean id="stu3" class="cn.kgc.kb08.spring.entity.Student" factory-bean="stuFactory" factory-method="get"/> <bean id="config" class="cn.kgc.kb08.spring.dao.SqlConfig"> <property name="driver" value=""/> <property name="url" value=""/> <property name="username" value=""/> <property name="password" value=""/><!--基本類型--> </bean> <bean id="baseDao" class="cn.kgc.kb08.spring.dao.BaseDao"> <constructor-arg index="0" ref="config"/> <!--應用類型:ref--> </bean>
相关推荐
杜鲁门 2020-11-05
与卿画眉共浮生 2020-10-14
lukezhong 2020-10-14
tangxiong0 2020-09-03
YangHuiLiang 2020-08-06
编程点滴 2020-07-29
smalllove 2020-07-27
iconhot 2020-07-05
XGQ 2020-07-04
MicroBoy 2020-07-04
itjavashuai 2020-07-04
zmysna 2020-07-04
willluckysmile 2020-06-29
CoderBoy 2020-06-28
爱莲说 2020-06-26
itjavashuai 2020-06-25
HappyHeng 2020-06-21
smalllove 2020-06-14
yuanye0 2020-06-14