<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
<!--bea标签通过默认构造方法创建对象-->
<bean id="apple" class="Spring.ioc.entity.Apple">
</bean>
<!--bean标签通过带参构造方法创建对象并初始化-->
<bean id="appleA" class="Spring.ioc.entity.Apple">
<constructor-arg name="brade" value="大苹果"/>
<constructor-arg name="color" value="紫色"/>
<constructor-arg name="origin" value="巴西"/>
<constructor-arg name="price" value="13"/><!--自动将字符串转为Float-->
</bean>
<!--通过类的setter方法,反射技术进行静态数值的注入-->
<!--ID是上层调用的标识符,class底层的类-->
<bean id="sweetApple" class="Spring.ioc.entity.Apple">
<property name="brade" value="红富士"></property>
<property name="origin" value="欧洲"></property>
<property name="color" value="红色"></property>
</bean>
<bean id="suanApple" class="Spring.ioc.entity.Apple">
<property name="brade" value="青苹果"></property><!--底层类的属性-->
<property name="origin" value="中亚"></property>
<property name="color" value="绿色"></property>
</bean>
<bean id="softApple" class="Spring.ioc.entity.Apple">
<property name="brade" value="金帅"/>
<property name="origin" value="中国"/>
<property name="color" value="黄色"/>
</bean>
<!--通过类的setter方法,反射技术进行对象注入,建立了依赖关系-->
<bean id="lily" class="Spring.ioc.entity.Child">
<property name="name" value="丽丽"/>
<property name="apple" ref="sweetApple"/>
</bean>
<bean id="andy" class="Spring.ioc.entity.Child">
<property name="name" value="安迪"/>
<property name="apple" ref="suanApple"/>
</bean>
<bean id="luna" class="Spring.ioc.entity.Child">
<property name="name" value="露娜"/>
<property name="apple" ref="softApple"/>
</bean>
<!-- ??? -->
<!--静态工厂实例化对象-->
<bean id="appleB" class="Spring.ioc.factory.AppleStaticFactory" factory-method="createSweetApple">
</bean>
<!--工厂实例方法实例化对象-->
<bean id="factoryInstance" class="Spring.ioc.factory.AppleFactoryInstance" />
<bean id="apple5" factory-bean="factoryInstance" factory-method="createNewInstance"/>
</beans>
06-03
1277
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交