The spring used to simplify the namespace p bean configuration

Under normal circumstances, we are such a configuration bean:

    <bean id="car1" class="com.gong.spring.beans.Car">
        <property name="name" value="baoma"></property>
    </bean>
    <bean id="car2" class="com.gong.spring.beans.Car">
        <property name="name" value="benchi"></property>
    </bean>
    <bean id="car3" class="com.gong.spring.beans.Car">
        <property name="name" value="binli"></property>
    </bean>
    
    <bean id="student" class="com.gong.spring.beans.Student">
        <property name="name" value="tom"></property>
        <property name="age" value="12"></property>
        <property name="score" value="98.00"></property>
        <property name="cars" ref="cars">
        </property>
        
    </bean>
    
    <util:list id="cars">
        <ref bean="car1"/>
        <ref bean="car2"/>
        <ref bean="car3"/>
    </util:list>

Description: cars are a common set of Bean, Student, there are name, age, score and type List <Car> of car attributes.

After the introduction of namespaces, so we can be configured:

    <bean id="car1" class="com.gong.spring.beans.Car" p:name="baoma"></bean>
    <bean id="car2" class="com.gong.spring.beans.Car" p:name="benchi"></bean>
    <bean id="car3" class="com.gong.spring.beans.Car" p:name="binli"></bean>
    
    <bean id="student" class="com.gong.spring.beans.Student"
    p:name="tom" p:age="12" p:score="98.00" p:cars-ref="cars"></bean>
    
    <util:list id="cars">
        <ref bean="car1"/>
        <ref bean="car2"/>
        <ref bean="car3"/>
    </util:list>

Compared to the original, concise code a lot.

Guess you like

Origin www.cnblogs.com/xiximayou/p/12150383.html