上海千语创想科技有限公司
 175-2108-6175
网站建设资讯详细

Eclipse中安装Spring框架教程

日期:2022-08-07  作者:千语创想  浏览:6599

Eclipse中安装Spring

      1、查看eclipse版本(必须和Spring版本对应才行)

             ----->打开eclipse----->Help-------->About Eclipse IDE

       2、安装Spring IDE插件:

             1)Help->Install New Software

             2)选择Add,添加Name(可以随便取)和Location:http://dist.springsource.com/release/TOOLS/update/e4.10/

             3)勾选中下边四个和Spring相关的文件。Core/Spring IDE、Extensions/Spring IDE、Integrations/Spring IDE、Resources/Spring IDE四项

       3、 点Next直到选择I accpet the terms of the license agreements点Finish然后等待插件安装完成并提示重启。

          报错:An error occurred while collecting items to be installed session context was:(profile=D__eclipse_java-2018-12_eclipse,phase=org.eclipse.equinox.internal.p2.engine.phases.Collect, operand=, action=).Unable to read repository at http://download.springsource.com/release/TOOLS/update/3.9.7.RELEASE/e4.10/plugins/org.springframework.ide.eclipse.boot.properties.editor.source_3.9.7.201812201020-RELEASE.jar.

          Read timed out

        解决办法:

        打开Window->Preferences->Install/Update->Available software Sites,将Oracle Enterprise Pack For Eclipse改为disable

       4、查看安装是否成功

            点击菜单Help-->Welcome,如果找到Spring IDE项,恭喜你,安装成功了。

            如果没有找到,怎么办呢?接着往下操作

       5、安装失败了,你可以换一种方式安装了,先下载,下载地址:http://spring.io/tools3/sts/all

       6、打开菜单Help-->Install New Software...

       7、在弹出框install中点Add...按钮,Name栏输入localSpringIDE,在Location栏点击Archive...按钮,选择刚下载的springsource-tool-suite-x.x.x.RELEASE-e4.10.0-updatesite.zip,点OK按钮后依然在在列表框中勾选带Spring IDE的项,点下一步,然后根据提示直到安装完成,然后重启Eclipse即可。

      8、查看安装是否成功

三、Spring使用

       1、环境条件:

            1)windows 10系统

            2)eclipse(开发环境)

           3)Spring IDE(上面已经安装了) 地址:http://spring.io/tools3/sts/all

           4)Spring framework(一会儿要用的jar包)  地址:http://repo.spring.io/release/org/springframework/spring/

           5)commens-logging-x.x.x.jar 地址:http://commons.apache.org/proper/commons-logging/download_logging.cgi

       2、 新建一个java工程,名字就叫first_spring,创建一个包名demo,创建两个类分别为HelloWorld和Main,导入4个spring核心jar包(分别是:spring-beans-5.1.0.RELEASE.jar、spring-context-5.1.0.RELEASE.jar、spring-core-5.1.0.RELEASE.jar、spring-expression-5.1.0.RELEASE.jar)和1个外部依赖包(spring-expression-5.1.0.RELEASE.jar)。

    1)HelloWorld.java代码

package demo;

public class HelloWorld {

public void say(){

System.out.println("|-----------------------|");

System.out.println("|      hello world      |");

System.out.println("|-----------------------|");

}

}

     2)Main.java测试代码

import org.springframework.context.ApplicationContext;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

ApplicationContext a = new ClassPathXmlApplicationContext("classpath:/application.xml");

        HelloWorld helloWorld = (HelloWorld) a.getBean("helloWorld");

    helloWorld.say();

}

 

}

     3)application.xml配置文件


<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="helloWorld" class="demo.HelloWorld"></bean>

 

</beans>

     4)结果:成功


  

来千语创想移动应用开发平台学习更多APP开发知识:app开发app制作app开发源码下载app开发框架app制作模板等免费获取。

千语创想-专业APP开发app定制服务商,提供一站式移动应用解决方案,满足您的各类需求,欢迎免费评估需求和获取报价。



转载请注明来自:https://www.qianyuthink.com/news/7348.html

填写您的项目需求给我们

或者直接拨打 7×12小时一对一咨询电话

175 2108 6175

请填写需求信息,我们会在10分钟内与您取得联系

请认真填写需求信息,我们会在10分钟内与您取得联系

×
客服二维码
咨询技术总监
175-2108-6175
客服二维码
技术总监微信
客服二维码