把之前分享的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. GCC 编译选项

    http://www.cnblogs.com/xmphoenix/archive/2011/03/21/1989944.html GCC 编译选项(转) gcc提供了大量的警告选项,对代码中可能存在的 ...

  2. c++错误崩溃3

    使用了new申请了内存但是没有释放内存, 在程序长时间运行过程中不断的申请内存导致内存满了,再向内存写数据的时候回崩溃

  3. C#中MessageBox用法总结

    我们在程序中经常会用到MessageBox. MessageBox.Show()共有21中重载方法.现将其常见用法总结如下: 1.MessageBox.Show("Hello~~~~&quo ...

  4. mysql 主从不同步处理--数据库初始化

    问题处理借鉴至网上的内容 又一次做主从,全然同步 在主库新建一张表后.在slave 段发现数据没有同步过去. mysql version:5.6.10 os :rhel 5.6 解决过程例如以下: 1 ...

  5. 基于HTML5多图片Ajax上传可预览

    html5多图控件<input id="fileImage" type="file" size="30" name="fil ...

  6. JavaScript 中 关于 this 的学习笔记

    今天上午主要学习了js中的 this ,因为之前学习面向对象时,this这个东西出现的还是很频繁的,理解的很不透彻,感觉老被JAVA的思想带进坑里,所以对它特别关注. 首先贴一个大神的一篇博客,我是通 ...

  7. sql显示12个月数据

    需求 最近在做一个财务报表展示系统,Budget需要当月上传,还未上传月份的数据也需要显示出来. 数据库设计 cBudget表结构如下 CREATE TABLE [dbo].[cBudget]( ,) ...

  8. 【转】Python中执行cmd的三种方式

    原文链接:http://blog.csdn.net/menglei8625/article/details/7494094 目前我使用到的python中执行cmd的方式有三种: 1. 使用os.sys ...

  9. 分支-15. 日K蜡烛图

    /* * Main.c * 分支-15. 日K蜡烛图 * Created on: 2014年6月18日 * Author: Boomkeeper ****测试通过***** */ #include & ...

  10. getHibernateTemplate().find()

    find(String queryString, Object[] values); 这个方法后者的参数必须是一个数组,而不能是一个List. List ul=getHibernateTemplate ...