| |
28. 5. 15. 属性设定:网址 |
|
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="myUrl" value="http://www.java2java.com"/>
</bean>
</beans>
|
|
File: Main.java |
import java.net.URL;
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.getMyUrl());
}
}
class PropertyEditorTestBean {
private URL myUrl;
public URL getMyUrl() {
return myUrl;
}
public void setMyUrl(URL myUrl) {
this.myUrl = myUrl;
}
}
|
|
Download: Spring-PropertySettingURL.zip( 2,598 k) |
|