源码:

执行的代码

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. 鼠标滑过侧边弹出内容(JS)

    效果展示 实现原理 1. html结构: <div id="contain"> <span id="share">分享</span ...

  2. 洛谷P4578 [FJOI2018]所罗门王的宝藏(dfs)

    题意 题目链接 Sol 对于每个询问\(x, y, c\) 从在\((x, y)\)之间连一条边权为\(c\)的双向边,然后就是解\(K\)个二元方程. 随便带个数进去找找环就行了 #include& ...

  3. [C语言]易错知识点、小知识点复习(1)

    1. 计算机只能识别由0和1组成的二进制指令,需要将用高级语言(如C.C++)编写的源程序(.c..cpp)编译成二进制目标文件(.obj).一个程序可以根据需要写在不同的文件里,编译是以文件为单位进 ...

  4. How To Do Master Record Mass Maintenance

    How To Do Master Record Mass Maintenance Which master records mass maintenance can be done? What do ...

  5. RabbitMQ 消息流程、AMOP 概念

    AMOP Server:Broker.RabbitMQ Server,实现 AMOP 实体服务,接受客户端的连接 Conneciton:链接,应用程序与 Server 的网络连接 Channel:网络 ...

  6. Eclipse For JavaSE安装、配置、测试

    Eclipse For JavaSE安装.配置.测试(win7_64bit) 目录 1.概述 2.本文用到的工具 3.安装与配置 4.JavaSE开发测试 5.ADT安装与Android开发测试 6. ...

  7. 打包错误--Error:A problem was found with the configuration of task ':app:packageRelease'.

    解决办法: app目录下的build.gradle文件 将 shrinkResources 的值改为 false 或者直接去掉 shrinkResources true  表示 :打包的时候会去删除一 ...

  8. 深圳市共创力咨询为某大型上市企业提供两天的UCD内训与辅导服务!

    2017年5月23和24日两天,深圳市共创力咨询为国内某大型上市企业提供了为期两天的内训与辅导服务.本次执行培训与辅导任务的是UCD(基于用户体验的设计)资深顾问蔷薇女士.蔷薇老师分别从UCD理论.U ...

  9. python with open as f写中文乱码

    python3和python2的写法不一样具体如下: python3: with open(r'd:\ssss.txt','w',encoding='utf-8') as f: f.write(u'中 ...

  10. JHipster生成微服务架构的应用栈(二)- 认证微服务示例

    本系列文章演示如何用JHipster生成一个微服务架构风格的应用栈. 环境需求:安装好JHipster开发环境的CentOS 7.4(参考这里) 应用栈名称:appstack 认证微服务: uaa 业 ...