util独立Bean以及p命名空间为bean的属性赋值

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_38409944/article/details/82668076

使用util独立Bean 配置单例的集合bean,以供多个bean进行引用。(将属性放在外部,可供多个类应用,而不是一个具体的内部 相当于抽离代码)

     <util:list id="out">
        <ref bean="helloSet"></ref>
        <ref bean="helloSet"></ref>
    </util:list>
    <bean id="person" class="hello.Person">
        <property name="name"><value>大佬</value></property>
        <property name="hello" ref="out"></property>
    </bean>

通过p命名空间为bean的属性赋值,需要先导入p命名空间 ,相对传统的配置方式更加简洁:

     <util:list id="out">
        <ref bean="helloSet"></ref>
        <ref bean="helloSet"></ref>
    </util:list>
    <bean id="person" class="hello.Person" p:name="Spring" p:hello-ref="out"></bean>

猜你喜欢

转载自blog.csdn.net/qq_38409944/article/details/82668076