一、建立测试WebProject项目myproject,添加Spring支持;

二、新建类HelloWorld.java:

package com.cn.myproject.test;

public class HelloWorld {
protected String message;

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}
public String excute(){
return "Hello"+getMessage();
}
}


三、调用方法:

ApplicationContext ctx = new FileSystemXmlApplicationContext("classpath:../applicationContext.xml");
HelloWorld hello=(HelloWorld) ctx.getBean("HelloWorld");
System.out.println(hello.excute());


四、FileSystemXmlApplicationContext:

FileSystemXmlApplicationContext与ClassPathXmlApplicationContext有一些使用上的区别。网上参考资料较多,这里不赘述了。