spring中配置bean及引用


  spring 中配置一个list类型的bean之后,若想在类里面将其注入就不能用一般的@Inject标签了,
如下:配置简单的list
   <util:list id="systemAccountListZTL" list-class="java.util.ArrayList"
value-type="java.lang.String">
<value>xiaobo</value>
   </util:list>
   引用的时候须要用标签:
         @Resource(name="systemAccountListZTL")
        private List<String> systemAccountListZTL;
                此时如果用@Inject就会报错
   或者复杂的list配置如下
    <?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:batch="http://www.springframework.org/schema/batch"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:jms="http://www.springframework.org/schema/jms" xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.0.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">

<bean id="info" class="com.book511.service.product.ColumnInfo">
<property name="name" value="code" />
<property name="comments" value="请输入编号" />
<property name="required" value="true" />
<property name="type">
<value type="com.book511.service.product.ColumnInfo$Type">INPUT</value>
</property>
<property name="regex">
<null />
</property>
<property name="options">
<list>
<value>a</value>
<value>b</value>
</list>
</property>
</bean>



<util:list id="StorageAddInfos">
<bean class="com.book511.service.product.ColumnInfo">
<property name="name" value="进价" />
<property name="comments" value="1、必填项。2、需为有效价格格式" />
<property name="required" value="true" />
<property name="type">
<value type="com.book511.service.product.ColumnInfo$Type">INPUT</value>
</property>
<property name="regex" value="^\d+(\.\d+)?$"/>
</bean>
<bean class="com.book511.service.product.ColumnInfo">
<property name="name" value="入库数量" />
<property name="comments" value="1、必填项。2、只能录入正整数" />
<property name="required" value="true" />
<property name="type">
<value type="com.book511.service.product.ColumnInfo$Type">INPUT</value>
</property>
<property name="regex" value="^[0-9]*[1-9][0-9]*$"/>
</bean>
<bean class="com.book511.service.product.ColumnInfo">
<property name="name" value="入库原因" />
<property name="comments" value="" />
<property name="required" value="true" />
<property name="type">
<value type="com.book511.service.product.ColumnInfo$Type">RADIO</value>
</property>
<property name="regex">
<null />
</property>
<property name="options">
<list>
<value>外购</value>
<value>内调</value>
<value>赠送</value>
<value>盘盈</value>
</list>
</property>
</bean>
<bean class="com.book511.service.product.ColumnInfo">
<property name="name" value="供货单位" />
<property name="comments" value="" />
<property name="required" value="false" />
<property name="type">
<value type="com.book511.service.product.ColumnInfo$Type">RADIO</value>
</property>
<property name="regex">
<null />
</property>
<property name="options">
<list>
<value>人民邮电出版社</value>
<value>机械出版社</value>
</list>
</property>
</bean>
</util:list>
</beans>

    



   

猜你喜欢

转载自suitors.iteye.com/blog/1095640