applicationContext.xml,springIOC配置文件

<?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>


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值