Spring依赖注入properties,Map,List

注入Properties #1

    <bean id="pro1" class="java.util.Properties">
        <constructor-arg>
            <props>
                <prop key="abc">aaaa</prop>
                <prop key="abc1">aaaa1</prop>
            </props>
        </constructor-arg>
    </bean>

注入Properties ~从文件中初始化

方法1:
    <bean id="pro2" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
        <property name="locations">
            <list>
                <value>config/xml/properties/config.properties</value>
                <value>/WEB-INF/conf/application.properties</value>
            </list>
        </property>
    </bean>
方法2:
<context:property-placeholder location="classpath:jdbc.properties" />

注入MAP

    <bean id="map1" class="java.util.HashMap">
        <constructor-arg>
            <map>
                <entry key="column1" value="1"/>
                <entry key="column2" value="2"/>
            </map>
        </constructor-arg>
    </bean>

注入List

    <bean id="list1" class="java.util.ArrayList">
       <constructor-arg>
           <list>
            <value>someString</value>
            <ref bean="someBean"/>
           </list>
       </constructor-arg>
   </bean>
阅读更多
文章标签: spring 注入list
个人分类: java spring
上一篇Spring transaction
下一篇代理-Cglib
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭