如何在myeclipse中安装spring插件

如何在myeclipse中安装spring插件,第1张

在myeclipse中安装spring插件的方法:

1、打开myEclipse, 新建一个maven工程, new Maven Project -->all catalog

2、选择 quickstart -->填写好artifact Id(这个随自己的喜好填写,其他的选项也可以按照自己的喜好来填写) -->finish

3、打开新建项目中 pom.xml文件. 在 <dependencies></dependencies>中添加Spring官网中提供的代码

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-context</artifactId>

<version>4.0.2.RELEASE</version>

</dependency>

4、保存, 然后myEclipse会自动联网下载Spring framework

下载好后, 如需要下载源码和javadoc的话可以右键项目 -->Maven4MyEclipse -->Download javaDoc 和 Download Sources

这就安装好了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框架的搭建了。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/bake/11382635.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-15
下一篇 2023-05-15

发表评论

登录后才能评论

评论列表(0条)

保存