其它版本参考此博客:https://blog.csdn.net/zhen_6137/article/details/79384798
添加下载好的压缩文件路径
然后,接受,完成,重启即可,出现一下界面即安装成功
编写一个helloWorld,新建一个Java Project
新建一个lib将spring必须依赖的包,导入进去,依赖的包在此处下载链接:
https://pan.baidu.com/s/1Gev5-YW_CERgTQxE2xFxNQ
提取码:xu86
src下新建一个包,保内建立两个java文件如下
package com.atguigu.spring.beans;
public class HelloWorld {
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 HelloWorld(){
System.out.println("HelloWorld's Constructor...");
}
}
package com.atguigu.spring.beans;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Main {
public static void main(String[] args){
//此段代码用Spring代码替换
/*
//创建HelloWorld的一个对象
HelloWorld helloWorld = new HelloWorld();
//为name属性赋值
helloWorld.setName("atguigu");*/
//1.创建Spring的IOC容器对象
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
//2.从IOC容器中获取Bean实例
HelloWorld helloWorld = (HelloWorld) ctx.getBean("helloWorld");
//3.调用hello方法
helloWorld.hello();
}
}
src下新建Spring Bean的配置文件
注意此文件必须建在src目录下,不能是包里,否则会报异常
<?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 -->
<bean id="helloWorld" class="com.atguigu.spring.beans.HelloWorld">
<property name="name" value="Spring"></property>
</bean>
</beans>
运行Main文件