Spring框架簡介

Spring Framework Overview

Spring框架簡介

Spring makes it easy to create Java enterprise applications. It provides everything you
need to embrace the Java language in an enterprise environment, with support for Groovy
and Kotlin as alternative languages on the JVM, and with the flexibility to create many
kinds of architectures depending on an application's needs. As of Spring Framework 5.1,
Spring requires JDK 8+ (Java SE 8+) and provides out-of-the-box support for JDK 11 LTS.
Java SE 8 update 60 is suggested as the minimum patch release for Java 8, but it is
generally recommended to use a recent patch release.java

Spring使得Java企業應用開發變得簡單。它提供了在企業環境中使用Java語言所須要的一切而且能夠根據應用的需求靈活的構建多種架構,同時也支持Groovy和Kotlin這些基於JVM使用的替代語言。從Spring框架5.1開始,使用Spring須要JDK8+(Java SE 8+)版本而且也提供了對JDK11 LTS版本的支持。建議將Java SE8第60個更新版本做爲使用Java8的最小修訂版本,可是一般推薦使用最新修訂版。react

Spring supports a wide range of application scenarios. In a large enterprise, applications
often exist for a long time and have to run on a JDK and application server whose upgrade
cycle is beyond developer control. Others may run as a single jar with the server embedded,
possibly in a cloud environment. Yet others may be standalone applications (such as batch
or integration workloads) that do not need a server.ios

Spring支持普遍的應用場景。在大型企業中,一般應用程序是長時間存在而且運行在一個更新週期不受開發人員控制的JDK和應用服務器上。其餘的可能就是運行在內嵌服務器或者雲環境上的一個獨立jar。還有一些可能就是不須要服務器的獨立應用程序(好比批處理或者集成負載)。git

Spring is open source. It has a large and active community that provides continuous feedback
based on a diverse range of real-world use cases. This has helped Spring to successfully
evolve over a very long time.github

Spring是開源項目,它擁有一個龐大且活躍的社區,而且可以從各類實際使用案例中獲得持續的反饋。這也是在Spring在長期發展中走向成功的緣由。web

What We Mean by "Spring"

咱們所說的「Spring」是什麼?

The term "Spring" means different things in different contexts. It can be used to refer to
the Spring Framework project itself, which is where it all started. Over time, other Spring
projects have been built on top of the Spring Framework. Most often, when people say
"Spring", they mean the entire family of projects. This reference documentation focuses on
the foundation: the Spring Framework itself.spring

「Spring」一詞在不一樣的上下中表明的含義不盡相同。它能夠表明着Spring Framework項目自己,也能夠說是它一切的開始。隨着時間的推移,也有不少其餘的Spring項目在Spring Framework基礎上開發出來。一般人們所說的「Spring」表明的是整個項目系列。本參考文檔重點關注的是Spring框架自身。服務器

The Spring Framework is divided into modules. Applications can choose which modules they need.
At the heart are the modules of the core container, including a configuration model and a
dependency injection mechanism. Beyond that, the Spring Framework provides foundational
support for different application architectures, including messaging, transactional data and
persistence, and web. It also includes the Servlet-based Spring MVC web framework and, in
parallel, the Spring WebFlux reactive web framework.架構

Spring框架被分紅了多個模塊,應用程序能夠在使用時選擇他們所須要的模塊。核心容器的核心模塊包含配置模式以及依賴注入機制。除此以外,Spring框架還提供了對不一樣應用架構的功能支持,包括消息傳遞、數據事務和持久化以及WEB。它還包含了基於Servlet的SpringMVC Web框架以及與之並行存在Spring WebFlux響應式Web框架。app

A note about modules: Spring's framework jars allow for deployment to JDK 9's module path
("Jigsaw"). For use in Jigsaw-enabled applications, the Spring Framework 5 jars come with
"Automatic-Module-Name" manifest entries which define stable language-level module names
("spring.core", "spring.context" etc) independent from jar artifact names (the jars follow
the same naming pattern with "-" instead of ".", e.g. "spring-core" and "spring-context").
Of course, Spring's framework jars keep working fine on the classpath on both JDK 8 and 9+.

關於模塊化注意點:Spring框架支持部署到JDK9的模塊化路徑("Jigsaw")。爲了在啓用Jigsaw的應用程序中使用,在Spring5的jar中加入了「Automatic-Module-Name」清單列表用於定義獨立於jar包名(這些jar遵循着相同的命名模式:使用「-」代替「.」,如:"spring-core"和"spring-context")的標準語言級別的模塊化名稱(好比"spring.core"和"spring.context")。固然,Spring框架jar在JDK8和JDK9+類路徑上很好的運行。

Design Philosophy

設計原理

When you learn about a framework, it’s important to know not only what it does but what
principles it follows. Here are the guiding principles of the Spring Framework:

當學習一個框架時,很重要的一點是不只要了解它的原理也要遵循它的設計原則。如下是Spring框架的指導原則。

  • 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使你儘量的推遲你的設計決策。好比:你能夠在不改變代碼的狀況經過切換配置提供功能的持久化。對於許多其餘的基礎架構問題以及與第三方API集成也是同樣的。
  • 多角度兼容。Spring具備靈活性且不去限制你該怎麼去作,支持具備不一樣視角的普遍應用需求。
  • 強大的向後兼容性。Spring的演變是被精心管理的,全部版本之間沒有重大的變化。Spring支持精心選擇的JDK版本以及第三方庫,以方便維護依賴於Spring的應用和第三方庫。
  • 重視API設計。Spring團隊在設計API上投入了大量的思考和時間,使其可以容易理解以及可以在多版本中長久的支持。
  • 高標準的代碼質量。Spring框架強調javadoc要有意義、保持最新以及含義準確。Spring框架能夠自豪的說,它是極少具備代碼結構簡潔而且包之間沒有循環依賴的項目之一。

Feedback and Contributions

反饋與貢獻

For how-to questions or diagnosing or debugging issues, we suggest using StackOverflow,
and we have a https://spring.io/questions[questions page] that lists the suggested tags to use.
If you're fairly certain that there is a problem in the Spring Framework or would like
to suggest a feature, please use the https://github.com/spring-pro...[GitHub Issues].

對於如何提問、診斷以及調試之類的問題,咱們建議使用StackOverflow,以及咱們的 https://spring.io/questions[問題頁面] 列出了一些使用建議標籤。若是你很是肯定Spring框架存在問題或者你想提出一些新功能,請到 https://github.com/spring-pro...[GitHub Issues]反饋。

If you have a solution in mind or a suggested fix, you can submit a pull request on
https://github.com/spring-pro...[Github]. However, please keep in mind
that, for all but the most trivial issues, we expect a ticket to be filed in the issue
tracker, where discussions take place and leave a record for future reference.

若是您有解決方案或者建議的解決方案,你能夠到 https://github.com/spring-pro...[Github]提交你的需求。可是請記住,除了一些瑣碎的問題,咱們但願將問題的討論記錄在問題追蹤中,以備未來做參考。

For more details see the guidelines at the
https://github.com/spring-pro...[CONTRIBUTING],
top-level project page.

有關更多的詳細信息,請參考頂級項目頁面的指南 https://github.com/spring-pro...[CONTRIBUTING]。

Getting Started

入門

If you are just getting started with Spring, you may want to begin using the Spring
Framework by creating a https://projects.spring.io/sp...[Spring Boot]-based
application. Spring Boot provides a quick (and opinionated) way to create a
production-ready Spring-based application. It is based on the Spring Framework, favors
convention over configuration, and is designed to get you up and running as quickly
as possible.

若是你剛剛開始使用Spring,你可能須要使用基於 https://projects.spring.io/sp...[Spring Boot]來建立一個Spring項目。Spring Boot提供了一個快速(且便捷)的方式來構建一個基於Spring的生產應用。它基於Spring框架而且旨在讓你可以快速上手運行一個項目,更傾向於約定優於配置。

You can use https://start.spring.io/[start.spring.io] to generate a basic project or follow
one of the https://spring.io/guides["Getting Started" guides], such as
https://spring.io/guides/gs/r...[Getting Started Building a RESTful Web Service].
As well as being easier to digest, these guides are very task focused, and most of them
are based on Spring Boot. They also cover other projects from the Spring portfolio that
you might want to consider when solving a particular problem.

你可使用 https://start.spring.io/[start.spring.io] 生成一個基礎項目工程或者根據如下指南 https://spring.io/guides["Getting Started" guides]操做,好比: https://spring.io/guides/gs/r...[Getting Started Building a RESTful Web Service]。這些指南大多數是基於Spring Boot開發的,很是注重操做而且易於上手。他們還包含了Spring工程系列中的其餘項目,你在解決問題可能須要考慮到他們。

本文由博客一文多發平臺 OpenWrite 發佈!
相關文章
相關標籤/搜索