把之前分享的spring框架整理一份放在这里。

整体架构:

Spring是一个轻量级的控制反转(IoC)和面向切面(AOP)的容器框架

框架图(选自:http://docs.spring.io/spring/docs/3.0.x/reference/overview.html):

core Container为spring的核心,实现了基于IoC的bean管理容器。上层的aop /Aspects都是基于他基础上实现的AOP。他们构成了spring的核心功能。

在IoC和AOP基础上,我们有扩展了数据层和web层

使用场景:

web应用使用场景:(springmvc + spring)

rpc应用使用场景:

IoC:

应用控制反转,对象在被创建的时候,由一个调控系统内所有对象的外界实体,将其所依赖的对象的引用,传递给它。也可以说,依赖被注入到对象中。所以,控制反转是,关于一个对象如何获取他所依赖的对象的引用,这个责任的反转。

IoC容器框架的类关系:

beanFactory 和 applicationContext的比较,applicationContext支持的功能更多:

applicationContext支持不同的信息源:ApplicationContext扩展了MessageSource接口,可以支持国际化的实现。

访问资源:ApplicationContext继承了DefaultResourceLoader的子类,提供ResourceLoader和Resource的支持

支持应用事件:ApplicationContext继承了ApplicationEventPublisher接口

applicationContext启动流程(AbstractApplicationContext):

ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory();

// Invoke factory processors registered as beans in the context.
invokeBeanFactoryPostProcessors(beanFactory); // Register bean processors that intercept bean creation.
registerBeanPostProcessors(beanFactory); // Instantiate all remaining (non-lazy-init) singletons.
finishBeanFactoryInitialization(beanFactory);

  

bean介绍:

按照注入bean的种类分类:

分为 普通bean和 FactoryBean

factoryBean 需要实现FactoryBean接口,应用于一个bean作为工厂方法产生不同的bean实例,常用于应用层框架的搭建,可以根据特定条件返回接口的不同实现

public interface FactoryBean<T> {

    T getObject() throws Exception;
Class<?> getObjectType();
boolean isSingleton(); }

bean的资源定义如何载入到容器:

xmlBeanFactory:

    public XmlBeanFactory(Resource resource, BeanFactory parentBeanFactory) throws BeansException {
super(parentBeanFactory);
this.reader.loadBeanDefinitions(resource);
}

applicationContext

编程式获取bean的方法

ApplicationContext context = new ClassPathXmlApplicationContext("JunitNoHsfApplicationContext.xml");
FuwuDao fuwuDao = (FuwuDao)context.getBean("fuwuDao");

Web应用程序bean实例化的配置

    <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:application.xml</param-value>
</context-param> <context-param>
<param-name>${contextClassKey}</param-name>
<param-value>com.taobao.data.fmp.spring.FmpApplicationContext</param-value>
</context-param> <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

bean的注册流程:

如何自定义bean标签

http://docs.spring.io/spring/docs/3.0.x/spring-framework-reference/html/extensible-xml.html#extensible-xml-parser

获取bean的流程:

bean的生命周期

生命周期中的扩展

  • 各类Aware接口
  • BeanPostProcessor接口
  • InitializingBean接口

spring在web中如何启动

bean的注解

@Autowired或@Resource

@Component(不推荐使用)、@Repository、@Service、@Controller

注解功能的实现原理

  • 注解标签的解析

<context:component-scan base-package="com.taobao.data.fmp" />

http\://www.springframework.org/schema/context=org.springframework.context.config.ContextNamespaceHandler

  • 实现注解功能用到的beanPostProcessor

AutowiredAnnotationBeanPostProcessor   CommondAnnotationBeanPostProcessor

PersistenceAnnotationBeanPostProcessor   RequiredAnnotationBeanPostProcessor

问题互动:

Bean 的循环依赖会报错吗

如何扩展一个bean的定义标签

Web applicationContext什么时候实例化 bean

AOP

面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术。

实现原理

webx介绍

http://www.openwebx.org/

webx是在spring基础上对标签解析这进行了更一步的扩张,是标签解析和bean载入模式更加灵活

spring框架详解的更多相关文章

  1. Spring框架详解介绍-基本使用方法

    1.Spring框架-控制反转(IOC) 2.Spring框架-面向切面编程(AOP) 3.Spring 内置的JdbcTemplate(Spring-JDBC) Spring框架-控制反转(IOC) ...

  2. spring框架详解: IOC装配Bean

    1 Spring框架Bean实例化的方式: 提供了三种方式实例化Bean. 构造方法实例化:(默认无参数) 静态工厂实例化: 实例工厂实例化: 无参数构造方法的实例化: <!-- 默认情况下使用 ...

  3. Spring 框架 详解 (四)------IOC装配Bean(注解方式)

    Spring的注解装配Bean Spring2.5 引入使用注解去定义Bean @Component  描述Spring框架中Bean Spring的框架中提供了与@Component注解等效的三个注 ...

  4. Spring 框架 详解 (三)-----IOC装配Bean

    IOC装配Bean: 1.1.1 Spring框架Bean实例化的方式: 提供了三种方式实例化Bean. * 构造方法实例化:(默认无参数) * 静态工厂实例化: * 实例工厂实例化: 无参数构造方法 ...

  5. Spring 框架 详解 (二)

    Spring的入门的程序: 1.1.1 下载Spring的开发包: spring-framework-3.2.0.RELEASE-dist.zip ---Spring开发包 * docs :sprin ...

  6. Spring 框架 详解 (一)

    Spring是分层的JavaSE/EE full-stack(一站式) 轻量级开源框架 * 分层: * SUN提供的EE的三层结构:web层.业务层.数据访问层(持久层,集成层) * Struts2是 ...

  7. 【59】Quartz+Spring框架详解

    什么是Quartz Quartz是一个作业调度系统(a job scheduling system),Quartz不但可以集成到其他的软件系统中,而且也可以独立运行的:在本文中"job sc ...

  8. Spring配置文件详解 – applicationContext.xml文件路径

    Spring配置文件详解 – applicationContext.xml文件路径 Java编程                 spring的配置文件applicationContext.xml的默 ...

  9. 【转载】Spring AOP详解 、 JDK动态代理、CGLib动态代理

    Spring AOP详解 . JDK动态代理.CGLib动态代理  原文地址:https://www.cnblogs.com/kukudelaomao/p/5897893.html AOP是Aspec ...

随机推荐

  1. 【LeetCode练习题】Climbing Stairs

    Climbing Stairs You are climbing a stair case. It takes n steps to reach to the top. Each time you c ...

  2. 创建渐进式jpeg图片

    <?php // Create an image instance $im = imagecreatefromjpeg('test.jpg');   // Enable interlancing ...

  3. cf #214div2

     Dima and Guards Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u S ...

  4. 两年前实习时的文档——Platform学习总结

    1  概述 驱动程序实际上是硬件与应用程序之间的中间层.在Linux操作系统中,设备驱动程序对各种不同的设备提供了一致的訪问接口,把设备映射成一个特殊的设备文件,用户程序能够像其它文件一样对设备文件进 ...

  5. Java生成PDF报表

    一.前言 前几天,做ASN条码收货模块,需要实现打印下载收货报表,经一番查找,选定iText--用于生成PDF文档的一个Java类库.废话不多说,进入正题. 二.iText简介 iText是著名的开放 ...

  6. ASP .Net Core 使用 Dapper 轻型ORM框架

    一:优势 1,Dapper是一个轻型的ORM类.代码就一个SqlMapper.cs文件,编译后就40K的一个很小的Dll. 2,Dapper很快.Dapper的速度接近与IDataReader,取列表 ...

  7. python运维开发(五)----模块、生成器

    内容目录 双层装饰器 字符串格式化 生成器和迭代器 递归 模块 双层装饰器 需求场景介绍: 现有用户登录系统,普通用户能查看自己相关信息的权限,管理员用户能查看所有用户的权限,可以做两个装饰器来实现需 ...

  8. ajax 数据回传

    response.getWriter().print(reval > 0 ? true : false); //=========================== Object[] str ...

  9. 嵌入式平台组件白盒测试gcov、lcov和genhtml 使用指导

    在嵌入式平台上使用了gtest白盒测试工具,覆盖了被测函数,但是不知道自己测试的效果如何,测试行覆盖率.函数覆盖率,分支覆盖率的数据. 便开始研究gcov这个代码覆盖率工具能否使用,来检查白盒测试的效 ...

  10. 管道通信之无名管道---pipe()

    pipe()函数在子进程产生之前就应该存在. 父子进程之间只进行一次传递 /*============================================ > Copyright ( ...