Eclipse创建spring框架已经创建第一个spring项目

523 阅读1分钟

一起养成写作习惯!这是我参与「掘金日新计划 · 4 月更文挑战」的第11天,点击查看活动详情

spring Framework下载

第一步:网址:spring.io
第二步:点击进入Spring FrameWork, 点击GitHub猫 可能会进不去,多刷新几次
第三步:下拉找到Access to Binaries (访问二进制文件 )
第四步:下拉找到(download)
第五步:依次找到 release -->> org -->> spring-framework -->> spring
第六步:点击spring 复制地址
第七步:(选版本,和自己eclipse符合)repo.spring.io/release/org…
第八步:选类型(集合文档) 我的下载:repo.spring.io/ui/api/v1/d…

导入包

  1. image.png
  2. 还需要导入一个外包,也就是日志包commons-logging-1.1.1.jar

  网站地址,请自行下载:www.jb51.net/softs/57739…

  (可以把这几个包方法哦Eclipse的JRE System包中,这样更加方便)

安装springide插件

1)打开Eclipse,点击Help->Install New Software

2)选择Add,添加Name(可以随便取)和Location:dist.springsource.com/release/TOO…

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

项目

1.File——new——java project 创建一个java项目 2.创建一个lib文件夹,把spring里面的jar包都复制进去 3.右键点击lib文件——Build Path,先确认Include,再单击Configure Bulid Path...在libraries标签下点——add JARs... 如果成功了,lib里面的jar包图形会变化 然后在src里面创建java类,并且在src里面新建一个spring-config.xml

hello

public class Hello {
    public void sleep() {
        System.out.println("I want sleep");
    }
    
    public void study() {
        System.out.println("I want study");
    }

test

 public static void main(String[] args) {
        //1.加载spring配置文件
        ApplicationContext app=new ClassPathXmlApplicationContext("application.xml");
        //获取配置对象,返回对象的需要强制转换成Hello类的
        Hello hello=(Hello)app.getBean("hello");
        hello.sleep();
        hello.study();
    }
    

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">

<!--配置文件的内容,id是在引用的名字,class是对应想要执行的类(这个必须要包含包路径)  -->
<bean id="hello" class="test.Hello"></bean>
 
</beans>

image.png