【spring源码-IOC】1. Spring中比较重要的类

本文深入浅出地介绍了Spring源码中关键的类,包括DefaultListableBeanFactory、XmlBeanFactory和AbstractAutowireCapableBeanFactory等,以及BeanDefinition的相关概念。通过一个简单的项目结构示例,阐述了Spring如何根据XML配置文件创建和管理Bean。同时,探讨了BeanDefinition在Spring容器中的作用,将配置信息转化为内部表示并存储在BeanDefinitionRegistry中,为后续的Bean创建提供依据。

本系列文章旨在让小白也可以轻松学习Spring源码

本节主要学习几个类。看Spring的源码之前,需要先了解其中几个比较重要的类,这几个类也是在看源码中经常看到的类,刚开始看不懂没关系,后面遇到这些类在回来看本节会有恍然大悟的感觉。

  • DefaultListabelBeanFactory
  • XmlBeanFactory
  • AbstractAutowireCapableBeanFactory
  • ConfigurableListabelBeanFactory
  • AbstractBeanDefinition
  • BeanDefinitionReader
  • BeanDefinitionRegistry
  • BeanDefinitionHolder

一、例子

创建一个Spring的项目有很多种方式,本系列主要讲解XML配置文件的方式来注册Bean和加载。

1. 项目结构

在这里插入图片描述

1.2 Person

package beans;

/**
 * @author 环杰
 * @date 2021/07/09
 */
public class Person {

    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;
    }

    @Override
    public String toString() {
        return "Person{" +
            "name='" + name + '\'' +
            ", age=" + age +
            '}';
    }
}

1.3

package org.example;

import beans.Person;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Hello worl
4.0.0 org.springframework spring-framework-bom 5.3.39 pom Spring Framework (Bill of Materials) Spring Framework (Bill of Materials) https://github.com/spring-projects/spring-framework Spring IO https://spring.io/projects/spring-framework Apache License, Version 2.0 https://www.apache.org/licenses/LICENSE-2.0 repo jhoeller Juergen Hoeller jhoeller@pivotal.io scm:git:git://github.com/spring-projects/spring-framework scm:git:git://github.com/spring-projects/spring-framework https://github.com/spring-projects/spring-framework GitHub https://github.com/spring-projects/spring-framework/issues org.springframework spring-aop 5.3.39 org.springframework spring-aspects 5.3.39 org.springframework spring-beans 5.3.39 org.springframework spring-context 5.3.39 org.springframework spring-context-indexer 5.3.39 org.springframework spring-context-support 5.3.39 org.springframework spring-core 5.3.39 org.springframework spring-expression 5.3.39 org.springframework spring-instrument 5.3.39 org.springframework spring-jcl 5.3.39 org.springframework spring-jdbc 5.3.39 org.springframework spring-jms 5.3.39 org.springframework spring-messaging 5.3.39 org.springframework spring-orm 5.3.39 org.springframework spring-oxm 5.3.39 org.springframework spring-r2dbc 5.3.39 org.springframework spring-test 5.3.39 org.springframework spring-tx 5.3.39 org.springframework spring-web 5.3.39 org.springframework spring-webflux 5.3.39 org.springframework spring-webmvc 5.3.39 org.springframework spring-websocket 5.3.39
最新发布
11-11
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值