zl程序教程

您现在的位置是:首页 >  后端

当前栏目

spring源码分析(一)IOC管理Bean

Spring源码 分析 管理 bean IOC
2023-09-11 14:17:07 时间

通过最简单的IOC 容器来跟踪一下 IOC是怎么管理Bean的;Spring IoC容器对Bean定义资源文件的定位,载入、解析和依赖注入的分析

方法调用图:不知道用什么画比较好,凑合看吧 ,长方形是类,椭圆是执行方法,箭头 方法调用顺序

IOC加载、解析、注册

A. 使用简单IOC容器

//初始化path 和classLoader,没有传自定义加载器则给默认加载器       
 ClassPathResource resource = new ClassPathResource("SpringContextConfig.xml");
        DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
        reader.loadBeanDefinitions(resource);
        HelloWorld helloWorld = (HelloWorld)factory.getBean("helloWorldImpl1");
        helloWorld.say();