源码:

执行的代码

public static void main(String[] args) {
ApplicationContext context=new ClassPathXmlApplicationContext("Beans.xml");
Hello hello1=(Hello)context.getBean("hello");
Hello hello2=(Hello)context.getBean("hello");
// hello.getMessage();
System.out.println(hello1==hello2);
}

Beans.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"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.1.xsd">
<aop:aspectj-autoproxy></aop:aspectj-autoproxy> <bean id="roleAspect" class="com.dy.spring.aop.aspect.RoleAspect"></bean>
<aop:config>
<aop:pointcut id="roleServiced" expression="execution(public * com.dy.spring.aop.aspect.RoleService.saveMsg(..))" />
<aop:aspect id="role" ref="roleAspect">
<aop:before method="beforeSave" pointcut-ref="roleServiced"/>
<aop:after method="afterSave" pointcut-ref="roleServiced"/>
<aop:after-returning method="afterReturning" pointcut-ref="roleServiced"/>
<aop:after-throwing method="afterThrowing" pointcut-ref="roleServiced"/>
</aop:aspect>
</aop:config> <bean id="roleService" class="com.dy.spring.aop.aspect.RoleService"></bean>
<!--
<bean id="student" class="com.dy.spring.ioc.Student" default-lazy-init="true">
-->
<bean id="student" class="com.dy.spring.ioc.Student">
<property name="name" value="jason"></property>
</bean> <bean id="hello" class="com.dy.spring.ioc.Hello" scope="prototype">
<property name="message" value="这是一个测试"/>
</bean>
</beans>

1.产生beanFactory

ApplicationContext context=new ClassPathXmlApplicationContext("Beans.xml");之后,
通过new DefaultListableBeanFactory(getInternalParentBeanFactory());产生beanfactory

2.beanfactory加载配置信息

new 对象beanDefinitionReader

XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(beanFactory);

loadBeanDefinitions(beanDefinitionReader);读取的配置信息load到这个对象中

XmlBeanDefinitionReader加载配置文件Beans.xml

3.初始化Bean

bean初始化具体的方法finishBeanFactoryInitialization

通过ctor.newInstance(args) 初始化bean

Spring(1)_Bean初始化的更多相关文章

  1. Spring(1)_Bean初始化_逻辑图

  2. 从启动日志看Spring IOC的初始化和Bean生命周期

    一.Tomcat中启动IoC容器的日志 启动Tomcat等容器时,控制台每次都打印出一些日志. 最近刚好在研究Spring源码,所以换个角度,从启动日志来简单的看看Spring的初始化过程! 以下是T ...

  3. Spring3实战第二章第一小节 Spring bean的初始化和销毁三种方式及优先级

    Spring bean的初始化和销毁有三种方式 通过实现 InitializingBean/DisposableBean 接口来定制初始化之后/销毁之前的操作方法: 优先级第二通过 <bean& ...

  4. Spring源码分析:Spring IOC容器初始化

    概述: Spring 对于Java 开发来说,以及算得上非常基础并且核心的框架了,在有一定开发经验后,阅读源码能更好的提高我们的编码能力并且让我们对其更加理解.俗话说知己知彼,百战不殆.当你对Spri ...

  5. 配置Spring的用于初始化容器对象的监听器

    <!-- 配置Spring的用于初始化容器对象的监听器 --> <listener> <listener-class>org.springframework.web ...

  6. 03.Spring IoC 容器 - 初始化

    基本概念 Spring IoC 容器的初始化过程在监听器 ContextLoaderListener 类中定义. 具体由该类的的 configureAndRefreshWebApplicationCo ...

  7. Spring MVC(1)Spring MVC的初始化和流程以及SSM的实现

    一.Spring MVC概述 1.Spring MVC 的架构 对于持久层而言,随着软件的发展,迁移数据库的可能性很小,所以在大部分情况下都用不到Hibernate的HQL来满足迁移数据库的要求.与此 ...

  8. 整理在Spring IOC容器初始化后可以处理特定逻辑的多种实现方式

    Spring框架的核心是依赖注入.切面:Spring Boot是在Spring框架的基础上为其提供许多默认配置.默认约定(约定优于配置),从而达到减少或减化配置进而可开箱即用.快速上手:Spring ...

  9. 48、[源码]-Spring容器创建-初始化事件派发器、监听器等

    48.[源码]-Spring容器创建-初始化事件派发器.监听器等 8.initApplicationEventMulticaster();初始化事件派发器: 获取BeanFactory 从BeanFa ...

随机推荐

  1. css实现div内一段文本的两端对齐

    在一个固定宽度的div内,使得P标签内的文本两端对齐: text-align: justify;text-justify:inter-ideograph; <!DOCTYPE html> ...

  2. canvas-9NonZeroAroundPrinciples.html

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. 4种方法实现Html转码

    <script> var HtmlUtil = { /*1.用浏览器内部转换器实现html转码*/ htmlEncode: function(html) { //1.首先动态创建一个容器标 ...

  4. 二进制安装 kubernetes 1.12(四) - 部署 Node 节点组件

    在 master 上操作 vi /etc/profile export PATH=/opt/kubernetes/bin:$PATH source /etc/profile 将 kubelet-boo ...

  5. JavaScript Hoisting(提升)

    Hoisting 是指 js 在执行代码前,默认会将变量的声明和函数的声明,提升到当前作用域顶端的行为. 这里要注意一下,只提升声明,例如: console.log(a); var a = 10; / ...

  6. JS对url进行编码和解码(三种方式区别)

    Javascript语言用于编码的函数,一共有三个,最古老的一个就是escape().虽然这个函数现在已经不提倡使用了,但是由于历史原因,很多地方还在使用它,所以有必要先从它讲起. escape 和 ...

  7. CentOS7 离线安装MySQL

    1.删除原有的mariadb 不然安装报错 rpm -qa|grep mariadb rpm -e --nodeps mariadb-libs 2. 下载RPM安装包 在https://dev.mys ...

  8. ionic APP二维码插件 地址

     二维码插件地址第一个   https://github.com/kyocn/BarcodeScanner git网址 下载网址  https://github.com/kyocn/BarcodeSc ...

  9. ie6常见的兼容性问题

    1.<!DOCTYPE HTML>文档类型的声明. 产生条件:IE6浏览器,当我们没有书写这个文档声明的时候,会触发IE6浏览器的怪异解析现象: 解决办法:书写文档声明. 2.不同浏览器当 ...

  10. robot framework笔记(一):环境配置(基于python3)+在pycharm中编写及运行robot脚本

    (一)使用pip安装robotframework框架和seleniumlibrary库 pip install --upgrade robotframework pip install --upgra ...