源码:

执行的代码

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获取对象的长度

    var obj= { "name": "wuqian", "sex": "famale", "hello&qu ...

  2. HTML空格符号 nbsp; ensp; emsp; 介绍以及实现中文对齐的方法

    一:不同空格符合的区别   半角的不断行的空白格(推荐使用)    半角的空格    全角的空格 详细的含义:  :这是我们使用最多的空格,也就是按下space键产生的空格.在HTML中,如果你用空格 ...

  3. vuejs2.0与1.x版本中怎样使用js实时访问input的值的变化

    vuejs 2.0中js实时监听input 在2.0的版本中,vuejs把v-el 和 v-ref 合并为一个 ref 属性了,可以在组件实例中通过 $refs 来调用.这意味着 v-el:my-el ...

  4. HDU 1847 Good Luck in CET-4 Everybody!(找规律版巴什博奕)

    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...

  5. (jQuery插件)autocomplete插件的简单例子

    1.引入相应的js和css,我用到的时候是在jquery-ui的js里面整合的,ui的css 2.先在html上写一个input <input id="tags" class ...

  6. CentOS7中启动Tomcat后,8080端口不能被外部访问的解决办法。

    运行:/sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT

  7. SMM框架--maven创建web项目

    1.首先新建一个maven项目,看图: 2.按照以上步骤就可以创建一个maven项目,可以看到最下图的目录结构,但是这样的目录结构是不对的,需要做一些修改. 首先为了避免乱码,我们应该将项目编码换成U ...

  8. Linux唤醒抢占----Linux进程的管理与调度(二十三)

    1. 唤醒抢占 当在try_to_wake_up/wake_up_process和wake_up_new_task中唤醒进程时, 内核使用全局check_preempt_curr看看是否进程可以抢占当 ...

  9. jQuery设置radio、select、checkbox只读属性后,如何在后台得到数据

    1 设置表单的readonly属性 对于radio.select.checkbox来说,readonly属性对这三个标签不起什么作用. 2 设置表单的disabled属性 以radio为例说明. 代码 ...

  10. python——虚拟环境之virtualenvwrapper-win(windows10,64位)

    1 问题描述 当M个项目需要N个版本的python环境配置时(M>N)时,我们没有必要对每个项目都创建一个虚拟环境,只需要创建N个虚拟环境即可.这样节省了大量存储空间(特别是当M远大于N时).但 ...