myeclipse中怎么快速创建spring配置文件
展开全部
在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文件;
<beans>
<description>Spring Quick Start</description>
<!--该处bean中的name值必须是 其对应的class中的私有成员名
-->
<bean id="action1" class="UpperAction">
<property name="message">
<value>HeLLo</value>
</property>
</bean>
<bean id="action2" class="LowerAction">
<property name="message">
<value>HeLLo</value>
</property>
</bean>
</beans>
5、至此就完成了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文件;
<beans>
<description>Spring Quick Start</description>
<!--该处bean中的name值必须是 其对应的class中的私有成员名
-->
<bean id="action1" class="UpperAction">
<property name="message">
<value>HeLLo</value>
</property>
</bean>
<bean id="action2" class="LowerAction">
<property name="message">
<value>HeLLo</value>
</property>
</bean>
</beans>
5、至此就完成了spring框架的搭建了。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询