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 ...
随机推荐
- canvas-8clip.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- C#基础(201)--常量枚举
本文知识点: 1.掌握常量的定义和使用方法 2.理解枚举的作用和特点 3.掌握枚举的使用方法 1.1.常量的定义语法 const 数据类型 常量名称 = 值: 1.2.常见错误 1.3常量的 ...
- springboot 常用配置文件
1.连接数据库 <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId> ...
- Apache Beam WordCount编程实战及源码解读
概述:Apache Beam WordCount编程实战及源码解读,并通过intellij IDEA和terminal两种方式调试运行WordCount程序,Apache Beam对大数据的批处理和流 ...
- 在 Apex 中使用合并统计查询
SOQL 中的合并统计查询 在 SOQL 中,我们可以使用一系列函数来进行合并统计查询.它们的功能和标准 SQL 中的 SUM(),COUNT() 等函数类似. 官方文档 Apex 中使用合并统计查询 ...
- Codeup
问题 I: 习题5-10 分数序列求和 时间限制: 1 Sec 内存限制: 12 MB提交: 611 解决: 537[提交][状态][讨论版][命题人:外部导入] 题目描述 有如下分数序列 求出次 ...
- Markdown:常用语法
1.标题 说明:一共可以6级标题,几级几个# 一级标题 #一级标题 2.代码 用前后扩上 Hello World! 3.代码块 用前后扩上 Hello World! 4.加粗 加粗了 **加粗了** ...
- MySQL 5.7开启二进制日志注意事项
最近才开始将部分MySQL 5.6升级到MySQL 5.7, 在开启MySQL的二进制日志时,发现MySQL 5.7 与MySQL 5.6已有细微区别.如果在my.cnf配置文件中,只设置了全局系统变 ...
- XSS攻击介绍
一.概念 XSS攻击全称跨站脚本攻击,是为不和层叠样式表(Cascading Style Sheets, CSS)的缩写混淆,故将跨站脚本攻击缩写为XSS,XSS是一种在web应用中的计算机安全漏洞, ...
- 关于SqlServer数据表操作
--修改表字段长度alter table Tbl_Count_User_Ref ALTER COLUMN CountName nvarchar(500);新增字段alter table 表名 add ...