2018-06-14 Spring Framework Overview 5.0

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可以轻松创建Java企业应用程序。 它提供了在企业环境中支持Java语言所需的一切,并支持Groovy和Kotlin作为JVM上的替代语言,并可根据应用程序的需求灵活地创建多种体系结构。 从Spring Framework 5.0开始,Spring需要JDK 8+(Java SE 8+),并且已经为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支持广泛的应用场景。 在大型企业中,应用程序通常存在很长时间,并且必须在升级周期超出开发人员控制的JDK和应用程序服务器上运行。 其他人可能会将嵌入式服务器作为单个jar运行,可能在云环境中运行。 而另一些可能是不需要服务器的独立应用程序(如批处理或集成工作负载)。

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是开源的。 它拥有一个庞大而活跃的社区,可根据各种实际用例提供持续的反馈。 这有助于Spring在很长一段时间内成功发展。

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项目本身,这是它开始的地方。 随着时间的推移,其他Spring项目已经建立在Spring框架之上。 大多数情况下,当人们说“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的Spring MVC Web框架以及Spring WebFlux反应式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.

关于模块的注意事项:Spring的框架jar允许部署到JDK 9的模块路径(“Jigsaw”)。 为了在启用Jigsaw的应用程序中使用,Spring Framework 5 jars带有“Automatic-Module-Name”清单条目,它定义了独立于jar伪影的稳定语言级别模块名称(“spring.core”,“spring.context”等) 名称(罐子遵循与“ - ”相同的命名模式,而不是“.”,例如“spring-core”和“spring-context”)。 当然,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年应运而生,以应对早期J2EE规范的复杂性。 虽然有人认为Java EE和Spring竞争激烈,但Spring实际上是对Java EE的补充。 Spring编程模型不支持Java EE平台规范; 相反,它集成了精心挑选的EE保护伞个人规格:

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)规范,应用程序开发人员可以选择使用这些规范来代替Spring框架提供的Spring特定机制。

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级别(例如Servlet 3.1+,JPA 2.1+)至少 - 同时在Java EE 8级别提供开箱即用的新API集成 (例如Servlet 4.0,JSON绑定API)在运行时遇到。 这使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.

随着时间的推移,Java EE在应用程序开发中的作用已经发生了变化。 在Java EE和Spring的早期阶段,创建应用程序以部署到应用程序服务器。 今天,在Spring Boot的帮助下,应用程序以易于云计算和云计算的方式创建,并且嵌入了Servlet容器并且可以轻松更改。 从Spring Framework 5开始,WebFlux应用程序甚至不直接使用Servlet API,而是可以在不是Servlet容器的服务器(如Netty)上运行。

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不断创新并不断发展。 除了Spring框架之外,还有其他项目,比如Spring Boot,Spring Security,Spring Data,Spring Cloud,Spring Batch等等。 重要的是要记住,每个项目都有自己的源代码库,问题跟踪器和释放节奏。 有关Spring项目的完整列表,请参阅spring.io/projects。

3. 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.
  • 在每个级别提供选择。 Spring允许您尽可能迟地推迟设计决策。例如,您可以通过配置切换持久性提供程序,而无需更改代码。许多其他基础架构问题和与第三方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.

-适应不同的观点。春天拥抱灵活性,并没有对如何完成事情持有自己的看法。它以不同的视角支持各种应用需求。

  • 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.
  • 保持强大的后向兼容性。 Spring的演化经过精心设计,几乎不会在版本之间发生重大变化。 Spring支持精心挑选的一系列JDK版本和第三方库,以方便维护依赖于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.

-关心API设计。 Spring团队花费了大量的精力和时间来制作直观的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.
  • 为代码质量设定高标准。 Spring框架强调有意义,最新,准确的Javadoc。它是少数几个可以声明干净的代码结构的程序之一,它们之间没有循环依赖关系。

4. Feedback and Contributions 反馈和贡献

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.

对于操作方法问题或诊断或调试问题,我们建议使用StackOverflow,并且我们有一个问题页面列出了要使用的建议标签。 如果您确信Spring框架存在问题或者想要推荐一个功能,请使用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.

如果你有一个解决方案或建议修复,你可以在Github上提交一个pull请求。 但是,请记住,除了最琐碎的问题外,我们希望在问题跟踪器中提交一张票据,在那里进行讨论并留下备案以备将来参考。

For more details see the guidelines at the CONTRIBUTING, top-level project page.

有关更多详细信息,请参阅CONTRIBUTING顶级项目页面上的指导。

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,您可能希望通过创建基于Spring Boot的应用程序来开始使用Spring Framework。 Spring Boot提供了一种快速(并且自以为是)的方式来创建一个生产就绪的基于Spring的应用程序。 它基于Spring Framework,支持惯例而不是配置,并且旨在让您尽快启动并运行。

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生成一个基本项目,或者按照“入门”指南之一,例如构建RESTful Web服务入门。 除了易于消化外,这些指南非常专注于任务,其中大部分都基于Spring Boot。 他们还涵盖了您在解决特定问题时可能需要考虑的Spring组合中的其他项目。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 206,602评论 6 481
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 88,442评论 2 382
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 152,878评论 0 344
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 55,306评论 1 279
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 64,330评论 5 373
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,071评论 1 285
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,382评论 3 400
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,006评论 0 259
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,512评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,965评论 2 325
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,094评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,732评论 4 323
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,283评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,286评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,512评论 1 262
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,536评论 2 354
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,828评论 2 345

推荐阅读更多精彩内容