spring 用JavaBean 配置List

来源:互联网 发布:手机淘宝排行榜在哪里 编辑:程序博客网 时间:2024/05/18 03:23

用数值配置spring装配的JavaBean内部的List类型很容易,下面介绍如何用javabean装配JavaBean中的List

Java代码

 

public class Test {

 <?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:aop="http://www.springframework.org/schema/aop"  

    xmlns:tx="http://www.springframework.org/schema/tx"  

  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd   

                     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd  

                 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">   

    <bean id="element0" class="com.beantest.Element">  

        <property name="id" value="1001"/>  

     <property name="name" value="hello"/>  

        <property name="url" value="http://www.baidu.com/"/>  

    </bean>  

    <bean id="element1" class="com.beantest.Element">  

        <property name="id" value="1002"/>  

        <property name="name" value="world"/>  

        <property name="url" value="http://www.google.com/"/>  

    </bean>  

   <bean id="test" class="com.beantest.Test">  

        <property name="elementList">  

            <list>  

                <ref bean="element0" />  

                <ref bean="element1" />  

            </list>  

        </property>  

    </bean>  

</beans>

原创粉丝点击