#自我介绍 小白一枚,距离上一篇文章好像过去很久很久了(无视这个吧~)。最近闲来无事,就想着看看Spring的源码,和大家一起学习。如果有不对的对方请大家提出来(你T喵的来打我啊o( ̄︶ ̄)o)~
#一、准备工作 本次的演示版本是最新的Spring5.1.0.RELEASE。开发工具使用idea2017.01版本。 #二、环境搭建 ##2.1、POM文件
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.1.0.RELEASE</version>
</dependency>
</dependencies>
##2.2、一个简答的实体类
public class User {
private Long id;
private String name;
private Integer age;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
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;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", name='" + name + '\'' +
", age=" + age +
'}';
}
}
##2.3、一份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="user" class="com.ricky.domain.User">
<property name="id" value="1"></property>
<property name="age" value="24"></property>
<property name="name" value="Ricky"></property>
</bean>
</beans>
##2.4、一个启动类测试类
package com.ricky;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class MySpringDemo {
public static void main(String[] args) {
ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext("ApplicationContext.xml");
System.out.println(context.getBean("user"));
}
}
##2.5整体目录结构
好了,话不多说。Begin Game!