在MyEclipse中快速配置spring框架的步骤如下:
1、建工程;
File -> New -> Project ->Web Project,"Project
Name":MySpringTest,然后"Finish";
2、导入spring包;
选中MySpringTest,右击,MyEclipse
-> Add Spring Capabilities……,都默认即可;
3、建立项目所需类;
(1)、接口Action:(MySpringTest ->
src -> New -> interface ,取名为Action)
public interface Action {
public String execute(String str);
}
(2)、实现接口Action的类UpperAction:(将其 message 属性与输入字符串相连接,并返回其大写形式。)
public class UpperAction implements Action{
private String message;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String execute(String str){
return (getMessage()+str).toUpperCase();
}
}
(3)、 实现接口Action的类LowerAction:
public class LowerAction implements Action {
private String message;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String execute(String str) {
return (getMessage() + str).toLowerCase();
}
}
(4)、做测试用的SimpleTest类:
public class SimpleTest {
public static void main(String args[]) {
SimpleTest test = new SimpleTest();
test.testQuickStart();
}
public void testQuickStart() {
ApplicationContext ctx = new FileSystemXmlApplicationContext(
"src/bean.xml");
Action action = (Action) ctx.getBean("action1");
System.out.println(action.execute("Rod Johnson"));
action = (Action) ctx.getBean("action2");
System.out.println(action.execute("jeckj"));
}
}
4、配置applicationContext.xml文件;
Spring Quick Start
HeLLo
HeLLo
5、至此就完成了spring框架的搭建了。