从整体上一步步Debug SpringIOC源码

一、准备工作

  1. 新建 tx.xml 文件定义含有两个bean信息的配置文件
<?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标签:让spring创建一个对象并放置在IOC容器内,一个bean标签就对应某个类的一个对象
    属性:
        id: 该bean对象的唯一标识符,bean的名称,不能重复的
        class: 需要创建对象的类型的全限定名,Spring通过反射机制创建该类的对象(要求:该类必须拥有无参构造方法)
    -->
    <bean id="a" class="com.yanferr.Cat">
        <property name="name" value="TomCat"></property>
    </bean>
    <bean id="b" class="com.yanferr.Dog">
        <property name="name" value="JamDog"></property>
    </bean>
</beans>

  1. 测试类中加载配置文件,从spring容器中获取bean
public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("tx.xml");
        Cat bean = context.getBean(Cat.class);
    }
  1. 接下来就是debug整个流程所用到的重点方法以及介绍
    在这里插入图片描述
  2. 下图为对context.getBean(Cat.class); debug过程中springIOC的执行方法
    在这里插入图片描述
  3. 最后是AOP相关的方法,可以从下图看出spring中是用到了cglib和jdk两种方式来实现动态代理的
    在这里插入图片描述
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值