怎么在MyEclipse中快速配置spring框架
1个回答
2017-02-06 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
在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框架的搭建了。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询