Spring bean配置细节

<?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:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
    <!--配置bean-->
    <bean id="helloTest" class="com.spring.HelloTest">
        <property name="name">
            <value><![CDATA[Shanghai^]]></value>
        </property>
    </bean>
    <bean id="car" class="com.spring.Car">
        <constructor-arg index="0" value="Audi"/>
        <constructor-arg index="1" value="Shanghai"/>
        <constructor-arg type="double" value="300000"/>
    </bean>
    <bean id="car2" class="com.spring.Car">
        <constructor-arg type="java.lang.String" value="BMW"/>
        <constructor-arg type="java.lang.String">
            <value><![CDATA[Shanghai^]]></value>
        </constructor-arg>
        <constructor-arg type="int"><value>250</value></constructor-arg>
    </bean>
    <bean id="person" class="com.spring.Person">
        <property name="name" value="Tom"/>
        <property name="age" value="20"/>
        <!--<property name="car" ref="car2"/>-->
        <property name="car"><null/></property>
    </bean>
    <bean id="person2" class="com.spring.Person">
        <property name="name" value="Tom"/>
        <property name="age" value="20"/>
        <!--<property name="car">-->
            <!--<ref bean="car2"></ref>-->
        <!--</property>-->
        <!--<property name="car">-->
            <!--<bean class="com.spring.Car">-->
                <!--&lt;!&ndash;<property name="brand" value="Tom"/>&ndash;&gt;-->
                <!--<constructor-arg value="Ford"></constructor-arg>-->
                <!--<constructor-arg value="changan"></constructor-arg>-->
                <!--<constructor-arg value="20000" type="double"></constructor-arg>-->
            <!--</bean>-->
        <!--</property>-->
    </bean>
    <bean id="person3" class="com.spring.Person">
        <constructor-arg value="Tom"></constructor-arg>
        <constructor-arg value="24"></constructor-arg>
        <constructor-arg><null/></constructor-arg>
    </bean>
    <!--<bean id="person4" class="com.spring.Person">-->
        <!--<constructor-arg value="Tom"></constructor-arg>-->
        <!--<constructor-arg value="24"></constructor-arg>-->
        <!--<constructor-arg>-->
            <!--<bean class="com.spring.Car">-->
                <!--&lt;!&ndash;<property name="brand" value="Tom"/>&ndash;&gt;-->
                <!--<constructor-arg value="Ford"></constructor-arg>-->
                <!--<constructor-arg value="changan"></constructor-arg>-->
                <!--<constructor-arg value="20000" type="double"></constructor-arg>-->
            <!--</bean>-->
        <!--</constructor-arg>-->
        <!--<constructor-arg ref="car"></constructor-arg>
        <property name="car.brand" value="brand"></property>-->
    <!--</bean>-->
    <bean id="person5" class="com.spring.Person">
        <property name="name" value="Tom"/>
        <property name="age" value="20"/>
        <property name="car">
            <list>
                <ref bean="car"></ref>
                <ref bean="car2"></ref>
                <bean class="com.spring.Car">
                <!--<property name="brand" value="Tom"/>-->
                <constructor-arg value="Ford"></constructor-arg>
                <constructor-arg value="changan"></constructor-arg>
                <constructor-arg value="20000" type="double"></constructor-arg>
                </bean>
            </list>
        </property>
    </bean>
    <bean id="newPerson" class="com.spring.NewPerson">
        <property name="name" value="lsd"></property>
        <property name="age" value="24"></property>
        <property name="cars">
            <map>
                <entry key="AA" value-ref="car"></entry>
                <entry key="BB" value-ref="car2"></entry>
                <entry key="CC">
                    <bean class="com.spring.Car">
                        <!--<property name="brand" value="Tom"/>-->
                        <constructor-arg value="Ford"></constructor-arg>
                        <constructor-arg value="changan"></constructor-arg>
                        <constructor-arg value="20000" type="double"></constructor-arg>
                    </bean>
                </entry>
            </map>
        </property>
    </bean>

    <!--配置prop属性值-->
    <bean id="dataSouce" class="com.spring.DataSouce">
        <property name="properties">
            <props>
                <prop key="user">lsd</prop>
            </props>
        </property>
    </bean>

    <!--配置独立的集合bean,多个bean可以单独使用-->
    <util:list id="cars">
        <ref bean="car"></ref>
        <ref bean="car2"></ref>
    </util:list>
    <bean id="person7" class="com.spring.Person">
        <property name="name" value="Tom"/>
        <property name="age" value="20"/>
        <property name="car" ref="cars"/>
    </bean>
    <!--通过p命名空间为bean的属性赋值-->
    <bean id="person8" class="com.spring.Person" p:age="30" ></bean>
</beans>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值