Spring(1)_Bean初始化
源码:
执行的代码
- 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初始化的更多相关文章
- Spring(1)_Bean初始化_逻辑图
- 从启动日志看Spring IOC的初始化和Bean生命周期
一.Tomcat中启动IoC容器的日志 启动Tomcat等容器时,控制台每次都打印出一些日志. 最近刚好在研究Spring源码,所以换个角度,从启动日志来简单的看看Spring的初始化过程! 以下是T ...
- Spring3实战第二章第一小节 Spring bean的初始化和销毁三种方式及优先级
Spring bean的初始化和销毁有三种方式 通过实现 InitializingBean/DisposableBean 接口来定制初始化之后/销毁之前的操作方法: 优先级第二通过 <bean& ...
- Spring源码分析:Spring IOC容器初始化
概述: Spring 对于Java 开发来说,以及算得上非常基础并且核心的框架了,在有一定开发经验后,阅读源码能更好的提高我们的编码能力并且让我们对其更加理解.俗话说知己知彼,百战不殆.当你对Spri ...
- 配置Spring的用于初始化容器对象的监听器
<!-- 配置Spring的用于初始化容器对象的监听器 --> <listener> <listener-class>org.springframework.web ...
- 03.Spring IoC 容器 - 初始化
基本概念 Spring IoC 容器的初始化过程在监听器 ContextLoaderListener 类中定义. 具体由该类的的 configureAndRefreshWebApplicationCo ...
- Spring MVC(1)Spring MVC的初始化和流程以及SSM的实现
一.Spring MVC概述 1.Spring MVC 的架构 对于持久层而言,随着软件的发展,迁移数据库的可能性很小,所以在大部分情况下都用不到Hibernate的HQL来满足迁移数据库的要求.与此 ...
- 整理在Spring IOC容器初始化后可以处理特定逻辑的多种实现方式
Spring框架的核心是依赖注入.切面:Spring Boot是在Spring框架的基础上为其提供许多默认配置.默认约定(约定优于配置),从而达到减少或减化配置进而可开箱即用.快速上手:Spring ...
- 48、[源码]-Spring容器创建-初始化事件派发器、监听器等
48.[源码]-Spring容器创建-初始化事件派发器.监听器等 8.initApplicationEventMulticaster();初始化事件派发器: 获取BeanFactory 从BeanFa ...
随机推荐
- es6 语法 (let 和const)
一.let 和const 1.let 只在自己声明的块作用域中有效: function test(){ let a = 'a'; var b = 'b'; for(let i =1;i<3;i+ ...
- SD Consultant Year End Activities
SD Consultant Year End Activities What are the year ending activities to be done for SAP SD? S.No ...
- (后端)SpringBoot中Mybatis打印sql(转)
原文地址:https://www.cnblogs.com/expiator/p/8664977.html 如果使用的是application.properties文件,加入如下配置: logging. ...
- gitlab汉化
是上一片,我已经介绍了,如何安装gitlab 这篇文章讲解一下如何安装使用汉化gitlab 如需要查看如何安装gitlab,请访问:https://www.cnblogs.com/ws17345067 ...
- Kotlin Native
Kotlin Native 不是 Jni 的概念,它不仅仅是要与底层代码比如 C.C++ 交互,而且还要绕过 Jvm 直接编译成机器码供系统运行.也就是说,Kotlin 准备丢掉 Java 这根拐杖了 ...
- python LeetCode 两数相除
近一个月一直在写业务,空闲时间刷刷leetcode,刷题过程中遇到了一道比较有意思的题目,和大家分享. 题目描述: 给定两个整数,被除数 dividend 和除数 divisor.将两数相除,要求不使 ...
- VScode快捷键、Chrome快捷键知识小总结和状态码
一.VS code的一些快捷键 Shift + Delete 删除一整行 ctrl + Delete 删除光标之后到标点的数据 Delete 删除光标之后 ...
- c# 采用datatable 快速导入数据至MSSQL的方法分享
转自:http://www.maomao365.com/?p=5613 摘要:下文讲述使用c#代码快速将dataTable导入至mssql数据库的方法 实现思路:需要将datatable调整为同目标表 ...
- List泛型与DataTable相互转换
public static class ExtensionMethods{/// <summary>/// 将List转换成DataTable/// </summary>/// ...
- ArcGIS Server服务器监控
最近项目上需要对服务器与ArcGISServer服务进行监控,做了一个初步的原型,实现了以下功能. 一.服务器监控 注册服务器 服务器运行状态监控 在线状态 CPU.内存.存储配置监控,由于现在很多采 ...