2017-11-21 05:28:00 +08:00
|
|
|
|
[[overview]]
|
|
|
|
|
= Spring Framework Overview
|
2017-09-18 18:16:47 +08:00
|
|
|
|
:toc: left
|
|
|
|
|
:toclevels: 1
|
|
|
|
|
:docinfo1:
|
2017-10-04 05:55:14 +08:00
|
|
|
|
|
2017-08-17 16:23:26 +08:00
|
|
|
|
Spring makes it easy to create Java enterprise applications. It provides everything you
|
2017-09-28 17:47:50 +08:00
|
|
|
|
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
|
2019-03-05 20:08:34 +08:00
|
|
|
|
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.
|
2019-09-05 20:04:43 +08:00
|
|
|
|
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.
|
2015-03-03 18:38:01 +08:00
|
|
|
|
|
2017-09-28 17:47:50 +08:00
|
|
|
|
Spring supports a wide range of application scenarios. In a large enterprise, applications
|
2017-08-17 16:23:26 +08:00
|
|
|
|
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.
|
2017-04-18 01:55:45 +08:00
|
|
|
|
|
2017-08-17 16:23:26 +08:00
|
|
|
|
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.
|
2017-04-18 01:55:45 +08:00
|
|
|
|
|
2017-10-19 02:24:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-10-04 05:55:14 +08:00
|
|
|
|
[[overview-spring]]
|
2017-09-18 18:16:47 +08:00
|
|
|
|
== What We Mean by "Spring"
|
2015-03-03 18:38:01 +08:00
|
|
|
|
|
2017-09-28 17:47:50 +08:00
|
|
|
|
The term "Spring" means different things in different contexts. It can be used to refer to
|
2017-08-17 16:23:26 +08:00
|
|
|
|
the Spring Framework project itself, which is where it all started. Over time, other Spring
|
2017-09-28 17:47:50 +08:00
|
|
|
|
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.
|
2015-03-03 18:38:01 +08:00
|
|
|
|
|
2017-08-17 16:23:26 +08:00
|
|
|
|
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
|
2017-09-28 17:47:50 +08:00
|
|
|
|
persistence, and web. It also includes the Servlet-based Spring MVC web framework and, in
|
2017-08-17 16:23:26 +08:00
|
|
|
|
parallel, the Spring WebFlux reactive web framework.
|
2015-03-03 18:38:01 +08:00
|
|
|
|
|
2017-09-28 17:47:50 +08:00
|
|
|
|
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
|
2021-09-10 21:38:42 +08:00
|
|
|
|
("spring.core", "spring.context", etc.) independent from jar artifact names (the jars follow
|
2017-09-28 17:47:50 +08:00
|
|
|
|
the same naming pattern with "-" instead of ".", e.g. "spring-core" and "spring-context").
|
2019-03-05 20:08:34 +08:00
|
|
|
|
Of course, Spring's framework jars keep working fine on the classpath on both JDK 8 and 9+.
|
2017-09-28 17:47:50 +08:00
|
|
|
|
|
2017-10-19 02:24:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-10-04 05:55:14 +08:00
|
|
|
|
[[overview-history]]
|
2017-09-18 18:16:47 +08:00
|
|
|
|
== History of Spring and the Spring Framework
|
2015-03-03 18:38:01 +08:00
|
|
|
|
|
2017-08-17 16:23:26 +08:00
|
|
|
|
Spring came into being in 2003 as a response to the complexity of the early
|
|
|
|
|
https://en.wikipedia.org/wiki/Java_Platform,_Enterprise_Edition[J2EE] specifications.
|
|
|
|
|
While some consider Java EE and Spring to be in competition, Spring is, in fact, complementary
|
2017-09-28 17:47:50 +08:00
|
|
|
|
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:
|
2015-03-03 18:38:01 +08:00
|
|
|
|
|
2017-07-28 21:38:38 +08:00
|
|
|
|
* Servlet API (https://jcp.org/en/jsr/detail?id=340[JSR 340])
|
2017-09-28 17:47:50 +08:00
|
|
|
|
* WebSocket API (https://www.jcp.org/en/jsr/detail?id=356[JSR 356])
|
|
|
|
|
* Concurrency Utilities (https://www.jcp.org/en/jsr/detail?id=236[JSR 236])
|
2017-07-28 21:38:38 +08:00
|
|
|
|
* JSON Binding API (https://jcp.org/en/jsr/detail?id=367[JSR 367])
|
|
|
|
|
* Bean Validation (https://jcp.org/en/jsr/detail?id=303[JSR 303])
|
2017-09-28 17:47:50 +08:00
|
|
|
|
* JPA (https://jcp.org/en/jsr/detail?id=338[JSR 338])
|
|
|
|
|
* JMS (https://jcp.org/en/jsr/detail?id=914[JSR 914])
|
|
|
|
|
* as well as JTA/JCA setups for transaction coordination, if necessary.
|
2015-03-03 18:38:01 +08:00
|
|
|
|
|
2017-08-17 16:23:26 +08:00
|
|
|
|
The Spring Framework also supports the Dependency Injection
|
|
|
|
|
(https://www.jcp.org/en/jsr/detail?id=330[JSR 330]) and Common Annotations
|
|
|
|
|
(https://jcp.org/en/jsr/detail?id=250[JSR 250]) specifications, which application developers
|
2017-09-28 17:47:50 +08:00
|
|
|
|
may choose to use instead of the Spring-specific mechanisms provided by the Spring Framework.
|
|
|
|
|
|
|
|
|
|
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.
|
2015-03-03 18:38:01 +08:00
|
|
|
|
|
2017-08-17 16:23:26 +08:00
|
|
|
|
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
|
2017-09-28 17:47:50 +08:00
|
|
|
|
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.
|
2015-03-03 18:38:01 +08:00
|
|
|
|
|
2017-08-17 16:23:26 +08:00
|
|
|
|
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 https://spring.io/projects[spring.io/projects] for
|
|
|
|
|
the complete list of Spring projects.
|
2015-03-03 18:38:01 +08:00
|
|
|
|
|
2017-10-19 02:24:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-10-04 05:55:14 +08:00
|
|
|
|
[[overview-philosophy]]
|
2017-09-18 18:16:47 +08:00
|
|
|
|
== Design Philosophy
|
2015-03-03 18:38:01 +08:00
|
|
|
|
|
2017-08-17 16:23:26 +08:00
|
|
|
|
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:
|
|
|
|
|
|
|
|
|
|
* 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
|
2018-10-25 21:15:58 +08:00
|
|
|
|
meaningful, current, and accurate javadoc. It is one of very few projects that can claim
|
2017-08-17 16:23:26 +08:00
|
|
|
|
clean code structure with no circular dependencies between packages.
|
2015-03-03 18:38:01 +08:00
|
|
|
|
|
2017-10-19 02:24:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-10-04 05:55:14 +08:00
|
|
|
|
[[overview-feedback]]
|
2017-09-18 18:16:47 +08:00
|
|
|
|
== Feedback and Contributions
|
2015-03-03 18:38:01 +08:00
|
|
|
|
|
2020-06-22 01:41:56 +08:00
|
|
|
|
For how-to questions or diagnosing or debugging issues, we suggest using Stack Overflow. Click
|
2020-06-22 17:38:04 +08:00
|
|
|
|
https://stackoverflow.com/questions/tagged/spring+or+spring-mvc+or+spring-aop+or+spring-jdbc+or+spring-r2dbc+or+spring-transactions+or+spring-annotations+or+spring-jms+or+spring-el+or+spring-test+or+spring+or+spring-remoting+or+spring-orm+or+spring-jmx+or+spring-cache+or+spring-webflux+or+spring-rsocket?tab=Newest[here]
|
2020-06-22 01:41:56 +08:00
|
|
|
|
for a list of the suggested tags to use on Stack Overflow. 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-projects/spring-framework/issues[GitHub Issues].
|
2015-03-03 18:38:01 +08:00
|
|
|
|
|
2017-08-17 16:23:26 +08:00
|
|
|
|
If you have a solution in mind or a suggested fix, you can submit a pull request on
|
|
|
|
|
https://github.com/spring-projects/spring-framework[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.
|
2015-03-03 18:38:01 +08:00
|
|
|
|
|
2021-04-27 13:18:23 +08:00
|
|
|
|
For more details see the guidelines at the {spring-framework-main-code}/CONTRIBUTING.md[CONTRIBUTING],
|
2017-10-25 11:19:45 +08:00
|
|
|
|
top-level project page.
|
2015-03-03 18:38:01 +08:00
|
|
|
|
|
2017-10-19 02:24:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-10-04 05:55:14 +08:00
|
|
|
|
[[overview-getting-started]]
|
2017-09-18 18:16:47 +08:00
|
|
|
|
== Getting Started
|
2015-03-03 18:38:01 +08:00
|
|
|
|
|
2017-08-17 16:23:26 +08:00
|
|
|
|
If you are just getting started with Spring, you may want to begin using the Spring
|
2019-03-21 06:48:14 +08:00
|
|
|
|
Framework by creating a https://projects.spring.io/spring-boot/[Spring Boot]-based
|
2017-08-17 16:23:26 +08:00
|
|
|
|
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.
|
|
|
|
|
|
2019-03-21 06:48:14 +08:00
|
|
|
|
You can use https://start.spring.io/[start.spring.io] to generate a basic project or follow
|
2017-08-17 16:23:26 +08:00
|
|
|
|
one of the https://spring.io/guides["Getting Started" guides], such as
|
|
|
|
|
https://spring.io/guides/gs/rest-service/[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.
|