spring ref &history&design philosophy

Spring Framework Overview

Spring是开发java application的通用框架,分为多个模块(modules),核心是core container,包括configuration model(配置模型)和dependency injection(依赖注入)Spring还能够为多种应用架构(application architecture)提供支持,包括messaging,transaction data, persistence(持久化),web。Spring也提供Servlet-based Spring MVC web framework和Spring WebFlux reactive web framework。html

History

Spring最先在2003年,因为J2EE过于复杂而被开发出来的。有人认为Spring和Java EE是竞争关系,但Spring更像是对Java EE的补充。Spring整合了一些EE的标准:java

  • Servlet API
  • WebSocket API
  • Concurrency Utilities(并发性)
  • JSON Binding API 简介
  • Bean Validation(数据校验) 简介
  • JPA
  • JMS
  • Dependency Injection and Common Annotations

Java EE在app开发中的角色在随时间变化。早期的时候,javaEE和Spring开发的应用是部署在application server上的,今天,在Spring Boot的帮助下开发变得友好且更加云端化(devops and cloud-friendly),嵌入Servelet容器,很是容易改变。在Spring Framework5中,一个webflux应用甚至不须要Servlet API并能够运行在不含Servlet容器的server上。react

Spring projects目前在逐渐丰富,创建在Spring Framework上的projects有Spring Boot,Spring Security,Spring Data,Spring Cloud,Spring Batch…web

Spring的design philosophy

  • Provide choice at every level 尽量容许不改动code的状况下变动design
  • Accommodate diverse perspectives 容许设计的灵活性
  • Maintain strong backward compatibility 对JDK和第三方库的高兼容性
  • Care about API design API被设计地简单易用
  • Set high standards for code quality 注意代码的整洁

IoC Container

Introduction

IoC: Inversion of Control(控制反转) 也可称为dependency injection(依赖注入), 定义: it is a process whereby objects define their dependencies (that is, the other objects they work with) only through constructor arguments, arguments to a factory method, or properties that are set on the object instance after it is constructed or returned from a factory method. 容器随后在建立bean时将依赖注入(把须要的对象传入)。这个过程事实上是对bean自身控制实例化或依赖定位(经过直接初始化类或相似Service Locator Pattern机制)的inverse,这就是为何叫Inversion of Control。spring

org.springframework.beans 和 org.springframework.context两个包是Spring Framework的IoC容器的基础。BeanFactory接口提供了能管理任何类型对象的高级配置机制。简单来讲BeanFactory提供了框架配置和基本的功能。ApplicationContextBeanFactory的子接口,它添加了更多特性企业级应用的功能。在Spring中,塑造应用骨架并被IoC容器管理的对象称为bean。一个bean是一个被IoC容器实例化(instantiated),组装(assembled),管理(managed)的对象,bean只是应用中众多对象中的一个。bean和它周围的依赖都会被容器的配置影响。json

Container Overview

org.springframework.context.ApplicationContext接口说明了IoC容器,容器负责实例化,配置,集成beans。容器经过阅读配置文件(configuration metadata)知道实例化(或配置,集成)哪些beans。configuration metadata能够是XML,Java annotations(注释)或java code。IoC能够传递对象以使应用更简练并丰富对象间的依赖。架构

Spring也提供ApplicationContext接口的一些实现,在实践中常常会建立ClassPathXmlApplicationContextFileSystemXmlApplicationContext的实例。XML是传统的定义configuration metadata的方法。你能够经过一些XML配置(修改配置为支持额外的格式)来让容器使用注释或代码做为metadata。(原文较难理解:you can instruct the container to use Java annotations or code as the metadata format by providing a small amount of XML configuration to declaratively enable support for these additional metadata formats)并发

在大部分application scenario中IoC容器实例化多个实例并不须要详尽的用户代码,好比说网页应用中建立一个boilerplate只须要几行代码的descriptor。若是使用Spring Tool Suite就甚至只须要鼠标点几下或者键盘敲几下。app

how Spring works(图):
Your application classes are combined with configuration metadata so that, after the ApplicationContext is created and initialized, you have a fully configured and executable system or application.
Spring IoC框架

相关文章
相关标签/搜索