# spring-framework-parent
**Repository Path**: tyros/spring-framework-parent
## Basic Information
- **Project Name**: spring-framework-parent
- **Description**: Spring学习源码
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2022-04-19
- **Last Updated**: 2022-07-01
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# [尚硅谷Spring框架视频教程(spring5源码级讲解)](https://www.bilibili.com/video/BV1Vf4y127N5)
# 个人笔记: [语雀文档](https://www.yuque.com/zhangshuaiyin/java/daggr3)
持续学习更新中......
项目使用 Maven 统一管理
# Maven 工程项目搭建
## 一、创建父 Maven 工程
### 1. 创建父模块统一管理
IDEA -> File -> New -> Project 选择 Maven 工程,这里只需要创建一个空的 Maven 工程即可,用于作为父模块统一管理依赖。
### 2. 配置 pom.xml
这里选择的 Spring 版本是 5.3.19,可以根据官网选择最新的稳定版学习。
说明:
这里依赖引入方式是 BOM 方式,在父模块引入 Spring BOM,子模块引入 Spring 的子模块时不需要声明版本号,便于在父模块中统一管理版本号,避免依赖版本冲突。
引入 BOM 的注意点:
1. dependencyManagement
2. pom
3. import
```xml
4.0.0
io.zsy
spring-framework-parent
pom
1.0
8
8
5.3.19
4.13.2
org.springframework
spring-framework-bom
${spring.version}
pom
import
junit
junit
${junit.version}
test
```
## 二、创建子工程测试
### 1. 创建子模块 spring-hello_world
File -> New -> Module 创建 Maven 子模块 hello_world。
需要注意的是,这里使用 IDEA 创建子模块会在父模块 pom.xml 文件中自动生成子模块的引用:
```xml
spring-hello_world
```
### 2. 配置 pom.xml
根据 Spring 模块图引入 4 个核心模块以供测试:

1. Beans
2. Core
3. Context
4. Expression
```xml
spring-framework-parent
io.zsy
1.0
4.0.0
spring-hello_world
org.springframework
spring-beans
org.springframework
spring-core
org.springframework
spring-context
org.springframework
spring-expression
```
### 3. 创建一个 java bean
```java
package io.zsy.hello;
/**
* @author zhangshuaiyin
* @date 2022/4/18 22:06
*/
public class User {
public void born() {
System.out.println("我出生了");
}
}
```
### 4. 注册到 Spring 容器
```xml
```
### 5. 测试
1. 加载Spring配置文件
2. 获取配置中注入的 bean 对象
3. 创建对象成功,调用成员方法
```java
package io.zsy.hello;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @author zhangshuaiyin
* @date 2022/4/18 22:09
*/
public class HelloWorldTests {
@Test
public void testBean() {
// 1. 加载Spring配置文件
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("bean.xml");
// 2. 获取配置中注入的 bean 对象
User user = context.getBean("id_user", User.class);
// 3. 创建对象成功,调用成员方法
user.born();
}
}
```
完整目录结构
