Spring - Bean实例化的几种配置

2019-11-14  本文已影响0人  沐兮_d64c

1,资源类

image.png
image.png

2,静态工厂实例化(很少用)

image.png
<bean id="testComponent" class="com.hzq.TestComponentFactory"
          factory-method="getTestComponent">
</bean>

2,实例工厂实例化(很少用)

image.png
<bean id="testComponentFactory" class="com.hzq.TestComponentFactory"></bean>
<bean id="testComponent" factory-bean="testComponentFactory" factory-method="getTestComponent"></bean>

3,无参构造函数实例化

<bean id="testComponent" class="com.lianjia.businessHubLoan.TestComponent"></bean>

4,有参构造函数实例化

<bean id="testService" class="com.lianjia.businessHubLoan.TestService">
        <constructor-arg index="0" name="component" value="testComponent"></constructor-arg>
</bean>
上一篇 下一篇

猜你喜欢

热点阅读