目录
原文可参考:原文
配置eclipse
1.打开Eclipse——Help——About Eclipse IDE查看eclpise版本号
下载spring的插件包
下载地址:
3.Eclipse——Install New Software…——Add——Archive…选择刚才下载的插件——Add——只用勾选四个IDE结尾的选项——一路next之后会让你选择重启,重启后就可以看到Spring IDE,安装成功!
记住一定要等着它自己提示你重启,不是你自己关掉重启
配置就算完成了
完成第一个实例
之后第一个实例还需要5个jar包的导入
直接点击这个:下载jar包
其他途径:
下载common-logging-1.1.jar包:
链接:https://pan.baidu.com/s/1PC0WM7uvs3r1_cNE8j_STg
提取码:3gi6
找到 common-logging-1.1.jar包
Spring Framework各个版本下载:https://repo.spring.io/release/org/springframework/spring/
下载完成之后,我们把Spring Framework的压缩文件解压,找到libs文件夹,在里面找到4个jar包,下面的四个spring
开头的jar包
打开eclipse,新建一个java project文件,随便命名如spring-1,然后新建一个lib文件夹,将这5个复制好的jar包直接粘贴到lib文件夹中
我们在src下新建一个包,随便命名,
这是HelloWorld里面的代码
package com.testdemo;
public class HellolWorld {
private String name;
public void setName(String name) {
System.out.println("SetName"+name);
this.name = name;
}
public void hello() {
System.out.println("hello"+name);
}
public HellolWorld() {
System.out.println("HelloWorld Constructor");
}
}
在src下面我们还需要新建一个Spring配置文件(Spring Bean Configuration File),右键--New--other--找到Spring文件夹下面的Spring Bean Configuration File点击Next确定即可。置文件命名为applicationContext.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 = "com.testdemo.HellolWorld">
<property name="name" value="nihao"></property>
</bean>
</beans>
这是Main类里面的代码
package com.testdemo;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Main {
public static void main(String[] args) {
ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
}
}
运行结果