源码:

执行的代码

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

Beans.xml文件

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xmlns:aop="http://www.springframework.org/schema/aop"
  6. xsi:schemaLocation="http://www.springframework.org/schema/beans
  7. http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
  8. http://www.springframework.org/schema/context
  9. http://www.springframework.org/schema/context/spring-context-4.1.xsd
  10. http://www.springframework.org/schema/aop
  11. http://www.springframework.org/schema/aop/spring-aop-4.1.xsd">
  12. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>
  13.  
  14. <bean id="roleAspect" class="com.dy.spring.aop.aspect.RoleAspect"></bean>
  15. <aop:config>
  16. <aop:pointcut id="roleServiced" expression="execution(public * com.dy.spring.aop.aspect.RoleService.saveMsg(..))" />
  17. <aop:aspect id="role" ref="roleAspect">
  18. <aop:before method="beforeSave" pointcut-ref="roleServiced"/>
  19. <aop:after method="afterSave" pointcut-ref="roleServiced"/>
  20. <aop:after-returning method="afterReturning" pointcut-ref="roleServiced"/>
  21. <aop:after-throwing method="afterThrowing" pointcut-ref="roleServiced"/>
  22. </aop:aspect>
  23. </aop:config>
  24.  
  25. <bean id="roleService" class="com.dy.spring.aop.aspect.RoleService"></bean>
  26. <!--
  27. <bean id="student" class="com.dy.spring.ioc.Student" default-lazy-init="true">
  28. -->
  29. <bean id="student" class="com.dy.spring.ioc.Student">
  30. <property name="name" value="jason"></property>
  31. </bean>
  32.  
  33. <bean id="hello" class="com.dy.spring.ioc.Hello" scope="prototype">
  34. <property name="message" value="这是一个测试"/>
  35. </bean>
  36. </beans>

1.产生beanFactory

  1. 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. es6 语法 (let 和const)

    一.let 和const 1.let 只在自己声明的块作用域中有效: function test(){ let a = 'a'; var b = 'b'; for(let i =1;i<3;i+ ...

  2. SD Consultant Year End Activities

    SD Consultant Year End Activities What are the year ending activities to be done for SAP SD?   S.No ...

  3. (后端)SpringBoot中Mybatis打印sql(转)

    原文地址:https://www.cnblogs.com/expiator/p/8664977.html 如果使用的是application.properties文件,加入如下配置: logging. ...

  4. gitlab汉化

    是上一片,我已经介绍了,如何安装gitlab 这篇文章讲解一下如何安装使用汉化gitlab 如需要查看如何安装gitlab,请访问:https://www.cnblogs.com/ws17345067 ...

  5. Kotlin Native

    Kotlin Native 不是 Jni 的概念,它不仅仅是要与底层代码比如 C.C++ 交互,而且还要绕过 Jvm 直接编译成机器码供系统运行.也就是说,Kotlin 准备丢掉 Java 这根拐杖了 ...

  6. python LeetCode 两数相除

    近一个月一直在写业务,空闲时间刷刷leetcode,刷题过程中遇到了一道比较有意思的题目,和大家分享. 题目描述: 给定两个整数,被除数 dividend 和除数 divisor.将两数相除,要求不使 ...

  7. VScode快捷键、Chrome快捷键知识小总结和状态码

           一.VS code的一些快捷键 Shift + Delete    删除一整行 ctrl + Delete     删除光标之后到标点的数据 Delete          删除光标之后 ...

  8. c# 采用datatable 快速导入数据至MSSQL的方法分享

    转自:http://www.maomao365.com/?p=5613 摘要:下文讲述使用c#代码快速将dataTable导入至mssql数据库的方法 实现思路:需要将datatable调整为同目标表 ...

  9. List泛型与DataTable相互转换

    public static class ExtensionMethods{/// <summary>/// 将List转换成DataTable/// </summary>/// ...

  10. ArcGIS Server服务器监控

    最近项目上需要对服务器与ArcGISServer服务进行监控,做了一个初步的原型,实现了以下功能. 一.服务器监控 注册服务器 服务器运行状态监控 在线状态 CPU.内存.存储配置监控,由于现在很多采 ...