zoukankan      html  css  js  c++  java
  • spring通过注解依赖注入和获取xml配置混合的方式

    spring的xml配置文件中某个<bean></bean>中的property的用法是什么样的?

    /spring-beans/src/test/java/org/springframework/beans/factory/xml/XmlBeanCollectionTests.java

    /spring-beans/src/test/resources/org/springframework/beans/factory/xml/collections.xml

    void org.springframework.beans.factory.xml.XmlBeanCollectionTests.testRefSubelement() throws Exception

    <bean id="jenny" class="org.springframework.tests.sample.beans.TestBean">
        <property name="name"><value>Jenny</value></property>
        <property name="age"><value>30</value></property>
        <property name="spouse">
        <!-- Could use id and href -->
            <ref local="david"/>
        </property>
    </bean>

    <bean id="david" class="org.springframework.tests.sample.beans.TestBean">
        <description>
            Simple bean, without any collections.这里是注释,spring不会解析
        </description>
        <property name="name">
            <description>The name of the user</description>
            <value>David</value>
        </property>
        <property name="age"><value>27</value></property>
    </bean>

    上面的蓝色属性值,spring通过set方法注入值。

    org.springframework.tests.sample.beans.TestBean这个类里面必须有上面属性的get和set方法,比如

    @Override
    public int getAge() {
        return age;
    }

    @Override
    public void setAge(int age) {
        this.age = age;
    }

    <property name="description"><value>Simple bean, without any collections.ok</value></property>

    这种方法可以获取description的值。

  • 相关阅读:
    添加右键菜单
    闭包和迭代器
    函数的进阶
    函数入门
    文件操作
    深浅拷贝
    小数据池和再谈编码
    字典
    list tuple
    int bool str
  • 原文地址:https://www.cnblogs.com/usual2013blog/p/4004247.html
Copyright © 2011-2022 走看看