eclipse配置Spring

1、从eclipse下载Spring工具

进入 help -- install new software... ,如下图:

点击 add ,按以下方式输入:

Name : Spring

Location : http://dist.springsource.com/release/TOOLS/update/e4.10/

之后点击 add ,等待一会儿会出现安装列表,我们选择带有 IDE 的四个组件进行安装。

安装完成后重启客户端。

二、下载Spring framework以及commons-logging
1、Spring framework下载

进入Spring framework下载对应的版本,如图:

选择对应的版本进入下载,此处选择 5.2.8.release

选择第一个下载包,等待下载。

2、commons-logging下载

进入 commons-logging-windows版下载支持windows的文件,若想下载其他类型,可以访问此处

三、eclipse环境配置

1、新建 Java Project 项目,右键选择项目,点击 Build Path -- Configure Build Path

2、添加commons-logging进入该项目路径

①点击 Libraries

②选择 Add External JARs

③进入文件夹,选择下载好的 commons-logging ,解压进入文件目录,选择 commons-logging-x.x.jar

3、添加Spring组件进入路径

依然按照上述顺序,点击 Add External JARs 进行文件路径选择,此时进入下载好的Spring framework 文件夹,如下图所示:

进入 libs ,此时,如下图所示:

我们需要将后缀形式为 RELEASE.jar 形式的包全部导入,导入结果如下图:

此时,Spring的配置已经完成了。
注:jdk版本:JavaSE-1.8
eclipse版本:2020-06 (4.16.0)

四、验证Spring安装是否完成

按照如下格式新建文件:

代码如下:

1、HelloWorld代码

复制代码
package com.tutorialspoint;
public class HelloWorld {
   private String message;
   public void setMessage(String message){
      this.message  = message;
   }
   public void getMessage(){
      System.out.println("Your Message : " + message);
   }
}

2、MainApp代码

复制代码
package com.tutorialspoint;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class MainApp {
public static void main(String[] args) {
      ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
      HelloWorld obj = (HelloWorld) context.getBean("helloWorld");
      obj.getMessage();
   }
}

3、Beans.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-3.0.xsd">

   <bean id="helloWorld" class="com.tutorialspoint.HelloWorld">
       <property name="message" value="Hello World!"/>
   </bean>

</beans>

注:该文件位于src文件下

运行MainApp,即可得到如下结果:

配置完成!!!

相关推荐
Chase_______15 分钟前
【Java基础 | 13】IO 流(下):缓冲流、转换流、序列化与综合案例
java·开发语言
itfallrain29 分钟前
Spring 构造器循环依赖排查:@RequiredArgsConstructor + @Lazy 到底有没有生效
数据库·python·spring
bush433 分钟前
嵌入式linux学习记录十二,mmap
java·linux·学习
源码宝37 分钟前
基于SpringCloud+UniApp的智慧工地云平台整体架构设计与实现
java·人工智能·spring cloud·源码·智慧工地·云平台
天文家1 小时前
深入理解装饰器与适配器:从设计模式到 Spring AOP 的工程实践
java·设计模式
贺国亚1 小时前
Spring-AI与LangChain4j
java·人工智能·spring
野生技术架构师1 小时前
2026 Java面试宝典(春招/社招/秋招通用):没有前言,只有答案,直接开背
java·开发语言·面试
mN9B2uk172 小时前
数据库的约束简介
java·数据库·sql
AI人工智能+电脑小能手2 小时前
【大白话说Java面试题 第99题】【Mysql篇】第29题:如何选择合适的分布式主键方案?
java·数据库·分布式·mysql·面试
极光代码工作室2 小时前
基于SpringBoot的任务管理系统
java·springboot·web开发·后端开发