| |
属性设置:属性 |
|
File: context.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="testBean" class="PropertyEditorTestBean">
<property name="myProperties">
<value>
firstname=f
lastname=l
</value>
</property>
</bean>
</beans>
File: Main.java
import java.util.Properties;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
public class Main {
public static void main(String[] args) throws Exception {
BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("context.xml"));
PropertyEditorTestBean testBean = (PropertyEditorTestBean) beanFactory.getBean("testBean");
System.out.println(testBean.getMyProperties());
}
}
class PropertyEditorTestBean {
private Properties myProperties;
public Properties getMyProperties() {
return myProperties;
}
public void setMyProperties(Properties myProperties) {
this.myProperties = myProperties;
}
}
|
|
Spring-PropertySettingProperties.zip( 2,599 k) |
Related examples in the same category |
|