当我们在说Spring的时候,到底是在说什么?

Spring是什么?

当我们说到Spring的时候通常可能表示两个意思,可能是指Spring家族,它包含了Spring Framework、Spring Boot、SpringCloud、Spring Data等;另外一个意思就是指的Spring Framework。我们这里说的Spring就是指Spring Framework,它是一个Java应用程序框架。

什么是框架呢?框架最直观的理解是给你搭好了架子,剩下的东西由你自己来填充。框架包含两层意思,首先是框,指的是具有约束性,你只能在这个框的基础上进行修改,不能随意发挥;二是架,架指的是支撑性,可以通过架子的支撑,免去你很多重复类型的工作。

理解了什么是框架,那Spring Framework企业级应用框架,让你能简单快捷的创建企业级应用程序。那它是怎么减轻你创建应用程序的工作量的呢,很简单,本来需要你做的事情,它帮你做了,比如业务对象的管理(创建、销毁等),你只需要关系业务内部的实现即可,Spring提供了优雅的抽象接口实现功能的组装和灵活的配置。

Spring Framework本身并没有提供太多的功能,它主要专注于你代码组织更加优雅,使其具有良好的灵活性和扩展性,同时它又集成业界优秀的解决方案,形成具体业务框架,避免重复造轮子,比如Spring MVC、Spring Cloud等。Spring家族的其他框架都是基于Spring Framework在特定领域上的延伸和实现。

Spring Framework的核心特征

  • Core technologies: dependency injection, events, resources, i18n, validation, data binding, type conversion, SpEL, AOP.
  • Testing: mock objects, TestContext framework, Spring MVC Test, WebTestClient.
    ta Access: transactions, DAO support, JDBC, ORM, Marshalling XML.
  • Spring MVC and Spring WebFlux web frameworks.
  • Integration: remoting, JMS, JCA, JMX, email, tasks, scheduling, cache.
  • Languages: Kotlin, Groovy, dynamic languages.

Spring Framework的设计哲学:

  • 提供多个层面的选择
  • 海纳百川
  • 向前兼容
  • 注重API设计
  • 注重代码质量
  • Provide choice at every level. Spring lets you defer design decisions as late as possible. For example, you can switch persistence providers through configuration without changing your code. The same is true for many other infrastructure concerns and integration with third-party APIs.
  • Accommodate diverse perspectives. Spring embraces flexibility and is not opinionated about how things should be done. It supports a wide range of application needs with different perspectives.
  • Maintain strong backward compatibility. Spring’s evolution has been carefully managed to force few breaking changes between versions. Spring supports a carefully chosen range of JDK versions and third-party libraries to facilitate maintenance of applications and libraries that depend on Spring.
  • Care about API design. The Spring team puts a lot of thought and time into making APIs that are intuitive and that hold up across many versions and many years.
  • Set high standards for code quality. The Spring Framework puts a strong emphasis on meaningful, current, and accurate javadoc. It is one of very few projects that can claim clean code structure with no circular dependencies between packages.

最常用的Spring成员

Spring Boot

Spring Boot作为Spring家族的一名成员,也是基于Spring Framework的,主要解决的问题就是实现Spring Framework的自动配置。通过Spring Framework通过代码加配置的方式为企业级应用提供了良好的灵活性和扩展性,但随着Spring Framework越来越强大,配置文件也越来越繁琐,需要配置大量的xml,Spring Boot框架就是为了解决这个问题,通过Spring Boot,几行代码就可以实现应用服务,减轻了Spring Framework配置的工作量。

核心特征:

Create stand-alone Spring applications
Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)
Provide opinionated ‘starter’ dependencies to simplify your build configuration
Automatically configure Spring and 3rd party libraries whenever possible
Provide production-ready features such as metrics, health checks and externalized configuration
Absolutely no code generation and no requirement for XML configuration

Spring Cloud

Spring Cloud为开发者提供快速构建一个分布式企业应用的通用模板,例如配置中心、服务发现、服务路由、服务熔断、服务代理、控制总线、一次性token、全局锁、leader选举、分布式session、集群状态等。

核心特征:

Distributed/versioned configuration
Service registration and discovery
Routing
Service-to-service calls
Load balancing
Circuit Breakers
Global locks
Leadership election and cluster state
Distributed messaging

主要组成:

  • Spring Cloud Config
  • Spring Cloud Netflix(Eureka, Hystrix, Zuul, Archaius, etc.).
  • Spring Cloud Bus
  • Spring Cloud Cloudfoundry(提供与Pivotal Cloud Foundry的集成)
  • Spring Cloud Open Service Broker(Open Service Broker API.)
  • Spring Cloud Cluster(Zookeeper, Redis, Hazelcast, Consul.)
  • Spring Cloud Consul(服务发现和配置)
    -Spring Cloud Security(负载均衡的OAuth2客户端和依赖Zuul代理的认证头)
  • Spring Cloud Sleuth(分布式链路跟踪Zipkin、HTrace、ELK)
  • Spring Cloud Data Flow
  • Spring Cloud Stream
  • Spring Cloud Stream App Starters
  • Spring Cloud Task
  • Spring Cloud Task App Starters
  • Spring Cloud Zookeeper
  • Spring Cloud Connectors
  • Spring Cloud Starters
  • Spring Cloud CLI
  • Spring Cloud Contract
  • Spring Cloud Gateway
  • Spring Cloud OpenFeign
  • Spring Cloud Pipelines
  • Spring Cloud Function

Spring MVC

Spring MVC是Spring Framework的一部分,全称Spring Web MVC,是基于Servlet API的原生web框架,主要解决的是web程序开发问题。通过Dispacher Servlet, ModelAndView和View Resolver让影院开发变得很容易。

同时Spring Framework还引入了一个基于reactive-stack的web框架叫做Spring WebFlux的框架。

你可能感兴趣的:(Spring,spring)