Spring Framework Overview
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.0, Spring requires JDK 8+ (Java SE 8+) and provides out-of-the-box support for JDK 9 already.
Spring可以輕松創(chuàng)建Java企業(yè)應(yīng)用程序怀骤。 它提供了在企業(yè)環(huán)境中支持Java語言所需的一切摧冀,并支持Groovy和Kotlin作為JVM上的替代語言,并可根據(jù)應(yīng)用程序的需求靈活地創(chuàng)建多種體系結(jié)構(gòu)。 從Spring Framework 5.0開始,Spring需要JDK 8+(Java SE 8+),并且已經(jīng)為JDK 9提供了開箱即用的支持。
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.
Spring支持廣泛的應(yīng)用場景廓译。 在大型企業(yè)中,應(yīng)用程序通常存在很長時(shí)間债查,并且必須在升級(jí)周期超出開發(fā)人員控制的JDK和應(yīng)用程序服務(wù)器上運(yùn)行非区。 其他人可能會(huì)將嵌入式服務(wù)器作為單個(gè)jar運(yùn)行,可能在云環(huán)境中運(yùn)行盹廷。 而另一些可能是不需要服務(wù)器的獨(dú)立應(yīng)用程序(如批處理或集成工作負(fù)載)征绸。
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.
Spring是開源的。 它擁有一個(gè)龐大而活躍的社區(qū)俄占,可根據(jù)各種實(shí)際用例提供持續(xù)的反饋管怠。 這有助于Spring在很長一段時(shí)間內(nèi)成功發(fā)展。
1. 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 Framework項(xiàng)目本身排惨,這是它開始的地方吭敢。 隨著時(shí)間的推移碰凶,其他Spring項(xiàng)目已經(jīng)建立在Spring框架之上。 大多數(shù)情況下鹿驼,當(dāng)人們說“Spring”時(shí)欲低,他們指的是整個(gè)項(xiàng)目系列。 本參考文檔重點(diǎn)介紹基礎(chǔ):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框架分為幾個(gè)模塊砾莱。 應(yīng)用程序可以選擇他們需要的模塊。 核心是核心容器的模塊凄鼻,包括配置模型和依賴注入機(jī)制腊瑟。 除此之外,Spring框架為不同的應(yīng)用程序體系結(jié)構(gòu)提供了基礎(chǔ)支持块蚌,包括消息傳遞闰非,事務(wù)數(shù)據(jù)和持久性以及Web。 它還包括基于Servlet的Spring MVC Web框架以及Spring WebFlux反應(yīng)式Web框架峭范。
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.
關(guān)于模塊的注意事項(xiàng):Spring的框架jar允許部署到JDK 9的模塊路徑(“Jigsaw”)财松。 為了在啟用Jigsaw的應(yīng)用程序中使用,Spring Framework 5 jars帶有“Automatic-Module-Name”清單條目,它定義了獨(dú)立于jar偽影的穩(wěn)定語言級(jí)別模塊名稱(“spring.core”辆毡,“spring.context”等) 名稱(罐子遵循與“ - ”相同的命名模式菜秦,而不是“.”,例如“spring-core”和“spring-context”)舶掖。 當(dāng)然球昨,Spring的框架jar在JDK 8和9的classpath上都能正常工作。
2. History of Spring and the Spring Framework. Spring框架的歷史
Spring came into being in 2003 as a response to the complexity of the early J2EE specifications. While some consider Java EE and Spring to be in competition, Spring is, in fact, complementary to Java EE. The Spring programming model does not embrace the Java EE platform specification; rather, it integrates with carefully selected individual specifications from the EE umbrella:
Spring于2003年應(yīng)運(yùn)而生眨攘,以應(yīng)對(duì)早期J2EE規(guī)范的復(fù)雜性褪尝。 雖然有人認(rèn)為Java EE和Spring競爭激烈,但Spring實(shí)際上是對(duì)Java EE的補(bǔ)充期犬。 Spring編程模型不支持Java EE平臺(tái)規(guī)范; 相反河哑,它集成了精心挑選的EE保護(hù)傘個(gè)人規(guī)格:
Servlet API (JSR 340)
WebSocket API (JSR 356)
Concurrency Utilities (JSR 236)
JSON Binding API (JSR 367)
Bean Validation (JSR 303)
JPA (JSR 338)
JMS (JSR 914)
as well as JTA/JCA setups for transaction coordination, if necessary.
The Spring Framework also supports the Dependency Injection (JSR 330) and Common Annotations (JSR 250) specifications, which application developers may choose to use instead of the Spring-specific mechanisms provided by the Spring Framework.
Spring框架還支持依賴注入(JSR 330)和Common Annotations(JSR 250)規(guī)范,應(yīng)用程序開發(fā)人員可以選擇使用這些規(guī)范來代替Spring框架提供的Spring特定機(jī)制龟虎。
As of Spring Framework 5.0, Spring requires the Java EE 7 level (e.g. Servlet 3.1+, JPA 2.1+) as a minimum - while at the same time providing out-of-the-box integration with newer APIs at the Java EE 8 level (e.g. Servlet 4.0, JSON Binding API) when encountered at runtime. This keeps Spring fully compatible with e.g. Tomcat 8 and 9, WebSphere 9, and JBoss EAP 7.
從Spring Framework 5.0開始璃谨,Spring需要Java EE 7級(jí)別(例如Servlet 3.1+,JPA 2.1+)至少 - 同時(shí)在Java EE 8級(jí)別提供開箱即用的新API集成 (例如Servlet 4.0鲤妥,JSON綁定API)在運(yùn)行時(shí)遇到佳吞。 這使Spring與例如 Tomcat 8和9,WebSphere 9和JBoss EAP 7棉安。
Over time, the role of Java EE in application development has evolved. In the early days of Java EE and Spring, applications were created to be deployed to an application server. Today, with the help of Spring Boot, applications are created in a devops- and cloud-friendly way, with the Servlet container embedded and trivial to change. As of Spring Framework 5, a WebFlux application does not even use the Servlet API directly and can run on servers (such as Netty) that are not Servlet containers.
隨著時(shí)間的推移底扳,Java EE在應(yīng)用程序開發(fā)中的作用已經(jīng)發(fā)生了變化。 在Java EE和Spring的早期階段贡耽,創(chuàng)建應(yīng)用程序以部署到應(yīng)用程序服務(wù)器衷模。 今天,在Spring Boot的幫助下蒲赂,應(yīng)用程序以易于云計(jì)算和云計(jì)算的方式創(chuàng)建阱冶,并且嵌入了Servlet容器并且可以輕松更改。 從Spring Framework 5開始滥嘴,WebFlux應(yīng)用程序甚至不直接使用Servlet API木蹬,而是可以在不是Servlet容器的服務(wù)器(如Netty)上運(yùn)行。
Spring continues to innovate and to evolve. Beyond the Spring Framework, there are other projects, such as Spring Boot, Spring Security, Spring Data, Spring Cloud, Spring Batch, among others. It’s important to remember that each project has its own source code repository, issue tracker, and release cadence. See spring.io/projects for the complete list of Spring projects.
Spring不斷創(chuàng)新并不斷發(fā)展若皱。 除了Spring框架之外镊叁,還有其他項(xiàng)目,比如Spring Boot走触,Spring Security晦譬,Spring Data,Spring Cloud饺汹,Spring Batch等等蛔添。 重要的是要記住,每個(gè)項(xiàng)目都有自己的源代碼庫,問題跟蹤器和釋放節(jié)奏迎瞧。 有關(guān)Spring項(xiàng)目的完整列表夸溶,請(qǐng)參閱spring.io/projects。
3. Design Philosophy 設(shè)計(jì)理念
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:
當(dāng)你了解一個(gè)框架時(shí)凶硅,重要的是不僅要知道它的功能缝裁,還要知道它遵循的原則。 以下是Spring框架的指導(dǎo)原則:
- 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.
- 在每個(gè)級(jí)別提供選擇足绅。 Spring允許您盡可能遲地推遲設(shè)計(jì)決策捷绑。例如,您可以通過配置切換持久性提供程序氢妈,而無需更改代碼粹污。許多其他基礎(chǔ)架構(gòu)問題和與第三方API的集成也是如此。
- 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.
-適應(yīng)不同的觀點(diǎn)首量。春天擁抱靈活性壮吩,并沒有對(duì)如何完成事情持有自己的看法。它以不同的視角支持各種應(yīng)用需求加缘。
- 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.
- 保持強(qiáng)大的后向兼容性鸭叙。 Spring的演化經(jīng)過精心設(shè)計(jì),幾乎不會(huì)在版本之間發(fā)生重大變化拣宏。 Spring支持精心挑選的一系列JDK版本和第三方庫沈贝,以方便維護(hù)依賴于Spring的應(yīng)用程序和庫。
- 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.
-關(guān)心API設(shè)計(jì)勋乾。 Spring團(tuán)隊(duì)花費(fèi)了大量的精力和時(shí)間來制作直觀的API宋下,并支持多種版本和多年。
- 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.
- 為代碼質(zhì)量設(shè)定高標(biāo)準(zhǔn)市俊。 Spring框架強(qiáng)調(diào)有意義杨凑,最新滤奈,準(zhǔn)確的Javadoc摆昧。它是少數(shù)幾個(gè)可以聲明干凈的代碼結(jié)構(gòu)的程序之一,它們之間沒有循環(huán)依賴關(guān)系蜒程。
4. Feedback and Contributions 反饋和貢獻(xiàn)
For how-to questions or diagnosing or debugging issues, we suggest using StackOverflow, and we have a 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 JIRA issue tracker.
對(duì)于操作方法問題或診斷或調(diào)試問題绅你,我們建議使用StackOverflow,并且我們有一個(gè)問題頁面列出了要使用的建議標(biāo)簽昭躺。 如果您確信Spring框架存在問題或者想要推薦一個(gè)功能忌锯,請(qǐng)使用JIRA問題跟蹤。
If you have a solution in mind or a suggested fix, you can submit a pull request on 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.
如果你有一個(gè)解決方案或建議修復(fù)领炫,你可以在Github上提交一個(gè)pull請(qǐng)求偶垮。 但是,請(qǐng)記住,除了最瑣碎的問題外似舵,我們希望在問題跟蹤器中提交一張票據(jù)脚猾,在那里進(jìn)行討論并留下備案以備將來參考。
For more details see the guidelines at the CONTRIBUTING, top-level project page.
有關(guān)更多詳細(xì)信息砚哗,請(qǐng)參閱CONTRIBUTING頂級(jí)項(xiàng)目頁面上的指導(dǎo)龙助。
5. Getting Started 入門
If you are just getting started with Spring, you may want to begin using the Spring Framework by creating a 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,您可能希望通過創(chuàng)建基于Spring Boot的應(yīng)用程序來開始使用Spring Framework蛛芥。 Spring Boot提供了一種快速(并且自以為是)的方式來創(chuàng)建一個(gè)生產(chǎn)就緒的基于Spring的應(yīng)用程序提鸟。 它基于Spring Framework,支持慣例而不是配置仅淑,并且旨在讓您盡快啟動(dòng)并運(yùn)行称勋。
You can use start.spring.io to generate a basic project or follow one of the "Getting Started" guides, such as 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.
您可以使用start.spring.io生成一個(gè)基本項(xiàng)目,或者按照“入門”指南之一涯竟,例如構(gòu)建RESTful Web服務(wù)入門铣缠。 除了易于消化外,這些指南非常專注于任務(wù)昆禽,其中大部分都基于Spring Boot蝗蛙。 他們還涵蓋了您在解決特定問題時(shí)可能需要考慮的Spring組合中的其他項(xiàng)目。