2019独角兽企业重金招聘Python工程师标准>>>
spring 5.1.5版本(一)
spring 5.1.5版本(二)
spring 5.1.5版本(三)
spring 5.1.5版本(四)
spring 5.1.5版本(五)
demo地址:https://gitee.com/gwlCode/springDemo
下载
1.进入spring官网:https://spring.io,点击 PROJECTS
2.选择 SPRING FRAMEWORK
3.选择 GitHub
4.选择 Spring Framework Artifacts
5.选择 http://repo.spring.io
6.依次选择 Artifacts -> libs-release-local -> org -> springframework -> spring,选择版本下载
7.下载后解压的目录为
导包
spring核心基础包
导入 commons-logging-1.2.jar,下载地址:http://commons.apache.org/proper/commons-logging/download_logging.cgi
测试
创建 User
package com.company.bean;
public class User {
private String name;
private Integer age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
}
配置 applicationContext.xml
获取User对象
package com.company.bean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Demo {
public static void main(String[] args) {
func();
}
static void func() {
//创建容器对象
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
//从容器取user对象
User user = (User) ac.getBean("user");
System.out.println(user);
}
}
获取结果