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的值。