日期:2014-05-20 浏览次数:21143 次
package com.gc.action;
import java.util.Date;
public class HelloWorld {
public String msg=null;
public Date date=null;
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public HelloWorld(Date date){
this.date=date;
}
}
<?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="HelloWorld" class="com.gc.action.HelloWorld" autowire="byName">
<property name="msg">
<value>1111</value>
</property>
</bean>
<bean id="date" class="java.util.Date"></bean>
</beans>
package com.gc.test; import java.io.FileNotFoundException; import org.springframework.context.ApplicationContext; import org.springframework.context.support.FileSystemXmlApplicationContext; import com.gc.action.HelloWorld; public class TestHelloWorld { /** * @param args * @throws FileNotFoundException */ public static void main(String[] args) throws FileNotFoundException { // TODO Auto-generated method stub ApplicationContext actx=new FileSystemXmlApplicationContext("config.xml"); HelloWorld helloWorld=(HelloWorld)actx.getBean("HelloWorld"); System.out.println(helloWorld.getDate()+":"+helloWorld.getMsg()); } }