Update API version and package references for Jakarta EE 9
Closes gh-27689 See gh-25354
This commit is contained in:
@@ -36,7 +36,7 @@ context`"). This section details how you can configure a Spring container (a
|
||||
|
||||
Moving on to specifics, all you need to do is declare a
|
||||
{api-spring-framework}/web/context/ContextLoaderListener.html[`ContextLoaderListener`]
|
||||
in the standard Java EE servlet `web.xml` file of your web application and add a
|
||||
in the standard Jakarta EE servlet `web.xml` file of your web application and add a
|
||||
`contextConfigLocation`<context-param/> section (in the same file) that defines which
|
||||
set of Spring XML configuration files to load.
|
||||
|
||||
@@ -102,7 +102,7 @@ on its specific integration strategies.
|
||||
== JSF
|
||||
|
||||
JavaServer Faces (JSF) is the JCP's standard component-based, event-driven web
|
||||
user interface framework. It is an official part of the Java EE umbrella but also
|
||||
user interface framework. It is an official part of the Jakarta EE umbrella but also
|
||||
individually usable, e.g. through embedding Mojarra or MyFaces within Tomcat.
|
||||
|
||||
Please note that recent versions of JSF became closely tied to CDI infrastructure
|
||||
|
||||
@@ -6,7 +6,7 @@ The original web framework included in the Spring Framework, Spring Web MVC, was
|
||||
purpose-built for the Servlet API and Servlet containers. The reactive-stack web framework,
|
||||
Spring WebFlux, was added later in version 5.0. It is fully non-blocking, supports
|
||||
https://www.reactive-streams.org/[Reactive Streams] back pressure, and runs on such servers as
|
||||
Netty, Undertow, and Servlet 3.1+ containers.
|
||||
Netty, Undertow, and Servlet containers.
|
||||
|
||||
Both web frameworks mirror the names of their source modules
|
||||
({spring-framework-main-code}/spring-webmvc[spring-webmvc] and
|
||||
@@ -23,16 +23,16 @@ in some cases, both -- for example, Spring MVC controllers with the reactive `We
|
||||
Why was Spring WebFlux created?
|
||||
|
||||
Part of the answer is the need for a non-blocking web stack to handle concurrency with a
|
||||
small number of threads and scale with fewer hardware resources. Servlet 3.1 did provide
|
||||
an API for non-blocking I/O. However, using it leads away from the rest of the Servlet API,
|
||||
where contracts are synchronous (`Filter`, `Servlet`) or blocking (`getParameter`,
|
||||
`getPart`). This was the motivation for a new common API to serve as a foundation across
|
||||
any non-blocking runtime. That is important because of servers (such as Netty) that are
|
||||
well-established in the async, non-blocking space.
|
||||
small number of threads and scale with fewer hardware resources. Servlet non-blocking I/O
|
||||
leads away from the rest of the Servlet API, where contracts are synchronous
|
||||
(`Filter`, `Servlet`) or blocking (`getParameter`, `getPart`). This was the motivation
|
||||
for a new common API to serve as a foundation across any non-blocking runtime. That is
|
||||
important because of servers (such as Netty) that are well-established in the async,
|
||||
non-blocking space.
|
||||
|
||||
The other part of the answer is functional programming. Much as the addition of annotations
|
||||
in Java 5 created opportunities (such as annotated REST controllers or unit tests), the addition
|
||||
of lambda expressions in Java 8 created opportunities for functional APIs in Java.
|
||||
in Java 5 created opportunities (such as annotated REST controllers or unit tests), the
|
||||
addition of lambda expressions in Java 8 created opportunities for functional APIs in Java.
|
||||
This is a boon for non-blocking applications and continuation-style APIs (as popularized
|
||||
by `CompletableFuture` and http://reactivex.io/[ReactiveX]) that allow declarative
|
||||
composition of asynchronous logic. At the programming-model level, Java 8 enabled Spring
|
||||
@@ -149,7 +149,7 @@ You have maximum choice of libraries, since, historically, most are blocking.
|
||||
|
||||
* If you are already shopping for a non-blocking web stack, Spring WebFlux offers the same
|
||||
execution model benefits as others in this space and also provides a choice of servers
|
||||
(Netty, Tomcat, Jetty, Undertow, and Servlet 3.1+ containers), a choice of programming models
|
||||
(Netty, Tomcat, Jetty, Undertow, and Servlet containers), a choice of programming models
|
||||
(annotated controllers and functional web endpoints), and a choice of reactive libraries
|
||||
(Reactor, RxJava, or other).
|
||||
|
||||
@@ -187,7 +187,7 @@ unsure what benefits to look for, start by learning about how non-blocking I/O w
|
||||
[[webflux-server-choice]]
|
||||
=== Servers
|
||||
|
||||
Spring WebFlux is supported on Tomcat, Jetty, Servlet 3.1+ containers, as well as on
|
||||
Spring WebFlux is supported on Tomcat, Jetty, Servlet containers, as well as on
|
||||
non-Servlet runtimes such as Netty and Undertow. All servers are adapted to a low-level,
|
||||
<<webflux-httphandler, common API>> so that higher-level
|
||||
<<webflux-programming-models, programming models>> can be supported across servers.
|
||||
@@ -205,7 +205,7 @@ used in the asynchronous, non-blocking space and lets a client and a server shar
|
||||
Tomcat and Jetty can be used with both Spring MVC and WebFlux. Keep in mind, however, that
|
||||
the way they are used is very different. Spring MVC relies on Servlet blocking I/O and
|
||||
lets applications use the Servlet API directly if they need to. Spring WebFlux
|
||||
relies on Servlet 3.1 non-blocking I/O and uses the Servlet API behind a low-level
|
||||
relies on Servlet non-blocking I/O and uses the Servlet API behind a low-level
|
||||
adapter. It is not exposed for direct use.
|
||||
|
||||
For Undertow, Spring WebFlux uses Undertow APIs directly without the Servlet API.
|
||||
@@ -305,7 +305,7 @@ applications:
|
||||
* For server request processing there are two levels of support.
|
||||
** <<webflux-httphandler, HttpHandler>>: Basic contract for HTTP request handling with
|
||||
non-blocking I/O and Reactive Streams back pressure, along with adapters for Reactor Netty,
|
||||
Undertow, Tomcat, Jetty, and any Servlet 3.1+ container.
|
||||
Undertow, Tomcat, Jetty, and any Servlet container.
|
||||
** <<webflux-web-handler-api>>: Slightly higher level, general-purpose web API for
|
||||
request handling, on top of which concrete programming models such as annotated
|
||||
controllers and functional endpoints are built.
|
||||
@@ -344,16 +344,16 @@ The following table describes the supported server APIs:
|
||||
| spring-web: Undertow to Reactive Streams bridge
|
||||
|
||||
| Tomcat
|
||||
| Servlet 3.1 non-blocking I/O; Tomcat API to read and write ByteBuffers vs byte[]
|
||||
| spring-web: Servlet 3.1 non-blocking I/O to Reactive Streams bridge
|
||||
| Servlet non-blocking I/O; Tomcat API to read and write ByteBuffers vs byte[]
|
||||
| spring-web: Servlet non-blocking I/O to Reactive Streams bridge
|
||||
|
||||
| Jetty
|
||||
| Servlet 3.1 non-blocking I/O; Jetty API to write ByteBuffers vs byte[]
|
||||
| spring-web: Servlet 3.1 non-blocking I/O to Reactive Streams bridge
|
||||
| Servlet non-blocking I/O; Jetty API to write ByteBuffers vs byte[]
|
||||
| spring-web: Servlet non-blocking I/O to Reactive Streams bridge
|
||||
|
||||
| Servlet 3.1 container
|
||||
| Servlet 3.1 non-blocking I/O
|
||||
| spring-web: Servlet 3.1 non-blocking I/O to Reactive Streams bridge
|
||||
| Servlet container
|
||||
| Servlet non-blocking I/O
|
||||
| spring-web: Servlet non-blocking I/O to Reactive Streams bridge
|
||||
|===
|
||||
|
||||
The following table describes server dependencies (also see
|
||||
@@ -484,9 +484,9 @@ The code snippets below show using the `HttpHandler` adapters with each server A
|
||||
server.start()
|
||||
----
|
||||
|
||||
*Servlet 3.1+ Container*
|
||||
*Servlet Container*
|
||||
|
||||
To deploy as a WAR to any Servlet 3.1+ container, you can extend and include
|
||||
To deploy as a WAR to any Servlet container, you can extend and include
|
||||
{api-spring-framework}/web/server/adapter/AbstractReactiveWebInitializer.html[`AbstractReactiveWebInitializer`]
|
||||
in the WAR. That class wraps an `HttpHandler` with `ServletHttpHandlerAdapter` and registers
|
||||
that as a `Servlet`.
|
||||
@@ -2400,7 +2400,7 @@ immediately next to the `@ModelAttribute`, as the following example shows:
|
||||
<1> Adding a `BindingResult`.
|
||||
|
||||
You can automatically apply validation after data binding by adding the
|
||||
`javax.validation.Valid` annotation or Spring's `@Validated` annotation (see also
|
||||
`jakarta.validation.Valid` annotation or Spring's `@Validated` annotation (see also
|
||||
<<core.adoc#validation-beanvalidation, Bean Validation>> and
|
||||
<<core.adoc#validation, Spring validation>>). The following example uses the `@Valid` annotation:
|
||||
|
||||
@@ -2747,7 +2747,7 @@ you can declare a concrete target `Object`, instead of `Part`, as the following
|
||||
----
|
||||
<1> Using `@RequestPart` to get the metadata.
|
||||
|
||||
You can use `@RequestPart` in combination with `javax.validation.Valid` or Spring's
|
||||
You can use `@RequestPart` in combination with `jakarta.validation.Valid` or Spring's
|
||||
`@Validated` annotation, which causes Standard Bean Validation to be applied. Validation
|
||||
errors lead to a `WebExchangeBindException` that results in a 400 (BAD_REQUEST) response.
|
||||
The exception contains a `BindingResult` with the error details and can also be handled
|
||||
@@ -2869,7 +2869,7 @@ and fully non-blocking reading and (client-to-server) streaming.
|
||||
You can use the <<webflux-config-message-codecs>> option of the <<webflux-config>> to
|
||||
configure or customize message readers.
|
||||
|
||||
You can use `@RequestBody` in combination with `javax.validation.Valid` or Spring's
|
||||
You can use `@RequestBody` in combination with `jakarta.validation.Valid` or Spring's
|
||||
`@Validated` annotation, which causes Standard Bean Validation to be applied. Validation
|
||||
errors cause a `WebExchangeBindException`, which results in a 400 (BAD_REQUEST) response.
|
||||
The exception contains a `BindingResult` with error details and can be handled in the
|
||||
|
||||
@@ -14,7 +14,7 @@ whose name, "`Spring WebFlux,`" is also based on its source module
|
||||
This section covers Spring Web MVC. The <<web-reactive.adoc#spring-web-reactive, next section>>
|
||||
covers Spring WebFlux.
|
||||
|
||||
For baseline information and compatibility with Servlet container and Java EE version
|
||||
For baseline information and compatibility with Servlet container and Jakarta EE version
|
||||
ranges, see the Spring Framework
|
||||
https://github.com/spring-projects/spring-framework/wiki/Spring-Framework-Versions[Wiki].
|
||||
|
||||
@@ -315,9 +315,9 @@ provides many extra convenient options.
|
||||
[[mvc-container-config]]
|
||||
=== Servlet Config
|
||||
|
||||
In a Servlet 3.0+ environment, you have the option of configuring the Servlet container
|
||||
programmatically as an alternative or in combination with a `web.xml` file. The following
|
||||
example registers a `DispatcherServlet`:
|
||||
In a Servlet environment, you have the option of configuring the Servlet container
|
||||
programmatically as an alternative or in combination with a `web.xml` file.
|
||||
The following example registers a `DispatcherServlet`:
|
||||
|
||||
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
|
||||
.Java
|
||||
@@ -1132,7 +1132,7 @@ request with a simple request parameter.
|
||||
`MultipartResolver` from the `org.springframework.web.multipart` package is a strategy
|
||||
for parsing multipart requests including file uploads. There is one implementation
|
||||
based on https://commons.apache.org/proper/commons-fileupload[Commons FileUpload] and
|
||||
another based on Servlet 3.0 multipart request parsing.
|
||||
another based on Servlet multipart request parsing.
|
||||
|
||||
To enable multipart handling, you need to declare a `MultipartResolver` bean in your
|
||||
`DispatcherServlet` Spring configuration with a name of `multipartResolver`.
|
||||
@@ -1163,9 +1163,9 @@ javadoc for details and configuration options.
|
||||
|
||||
|
||||
[[mvc-multipart-resolver-standard]]
|
||||
==== Servlet 3.0
|
||||
==== Servlet Multipart Parsing
|
||||
|
||||
Servlet 3.0 multipart parsing needs to be enabled through Servlet container configuration.
|
||||
Servlet multipart parsing needs to be enabled through Servlet container configuration.
|
||||
To do so:
|
||||
|
||||
* In Java, set a `MultipartConfigElement` on the Servlet registration.
|
||||
@@ -1205,7 +1205,7 @@ The following example shows how to set a `MultipartConfigElement` on the Servlet
|
||||
}
|
||||
----
|
||||
|
||||
Once the Servlet 3.0 configuration is in place, you can add a bean of type
|
||||
Once the Servlet multipart configuration is in place, you can add a bean of type
|
||||
`StandardServletMultipartResolver` with a name of `multipartResolver`.
|
||||
|
||||
[NOTE]
|
||||
@@ -2777,7 +2777,7 @@ alternatively, set `@ModelAttribute(binding=false)`, as the following example sh
|
||||
<1> Setting `@ModelAttribute(binding=false)`.
|
||||
|
||||
You can automatically apply validation after data binding by adding the
|
||||
`javax.validation.Valid` annotation or Spring's `@Validated` annotation
|
||||
`jakarta.validation.Valid` annotation or Spring's `@Validated` annotation
|
||||
(<<core.adoc#validation-beanvalidation, Bean Validation>> and
|
||||
<<core.adoc#validation, Spring validation>>). The following example shows how to do so:
|
||||
|
||||
@@ -3116,7 +3116,7 @@ When the `@RequestParam` annotation is declared as a `Map<String, MultipartFile>
|
||||
`MultiValueMap<String, MultipartFile>`, without a parameter name specified in the annotation,
|
||||
then the map is populated with the multipart files for each given parameter name.
|
||||
|
||||
NOTE: With Servlet 3.0 multipart parsing, you may also declare `jakarta.servlet.http.Part`
|
||||
NOTE: With Servlet multipart parsing, you may also declare `jakarta.servlet.http.Part`
|
||||
instead of Spring's `MultipartFile`, as a method argument or collection value type.
|
||||
|
||||
You can also use multipart content as part of data binding to a
|
||||
@@ -3218,7 +3218,7 @@ probably want it deserialized from JSON (similar to `@RequestBody`). Use the
|
||||
}
|
||||
----
|
||||
|
||||
You can use `@RequestPart` in combination with `javax.validation.Valid` or use Spring's
|
||||
You can use `@RequestPart` in combination with `jakarta.validation.Valid` or use Spring's
|
||||
`@Validated` annotation, both of which cause Standard Bean Validation to be applied.
|
||||
By default, validation errors cause a `MethodArgumentNotValidException`, which is turned
|
||||
into a 400 (BAD_REQUEST) response. Alternatively, you can handle validation errors locally
|
||||
@@ -3275,7 +3275,7 @@ The following example uses a `@RequestBody` argument:
|
||||
You can use the <<mvc-config-message-converters>> option of the <<mvc-config>> to
|
||||
configure or customize message conversion.
|
||||
|
||||
You can use `@RequestBody` in combination with `javax.validation.Valid` or Spring's
|
||||
You can use `@RequestBody` in combination with `jakarta.validation.Valid` or Spring's
|
||||
`@Validated` annotation, both of which cause Standard Bean Validation to be applied.
|
||||
By default, validation errors cause a `MethodArgumentNotValidException`, which is turned
|
||||
into a 400 (BAD_REQUEST) response. Alternatively, you can handle validation errors locally
|
||||
@@ -4350,7 +4350,7 @@ capital letters of the class and the method name (for example, the `getThing` me
|
||||
== Asynchronous Requests
|
||||
[.small]#<<mvc-ann-async-vs-webflux, Compared to WebFlux>>#
|
||||
|
||||
Spring MVC has an extensive integration with Servlet 3.0 asynchronous request
|
||||
Spring MVC has an extensive integration with Servlet asynchronous request
|
||||
<<mvc-ann-async-processing,processing>>:
|
||||
|
||||
* <<mvc-ann-async-deferredresult, `DeferredResult`>> and <<mvc-ann-async-callable, `Callable`>>
|
||||
@@ -4524,10 +4524,10 @@ methods for timeout and completion callbacks.
|
||||
==== Compared to WebFlux
|
||||
|
||||
The Servlet API was originally built for making a single pass through the Filter-Servlet
|
||||
chain. Asynchronous request processing, added in Servlet 3.0, lets applications exit
|
||||
the Filter-Servlet chain but leave the response open for further processing. The Spring MVC
|
||||
asynchronous support is built around that mechanism. When a controller returns a `DeferredResult`,
|
||||
the Filter-Servlet chain is exited, and the Servlet container thread is released. Later, when
|
||||
chain. Asynchronous request processing lets applications exit the Filter-Servlet chain
|
||||
but leave the response open for further processing. The Spring MVC asynchronous support
|
||||
is built around that mechanism. When a controller returns a `DeferredResult`, the
|
||||
Filter-Servlet chain is exited, and the Servlet container thread is released. Later, when
|
||||
the `DeferredResult` is set, an `ASYNC` dispatch (to the same URL) is made, during which the
|
||||
controller is mapped again but, rather than invoking it, the `DeferredResult` value is used
|
||||
(as if the controller returned it) to resume processing.
|
||||
|
||||
@@ -1258,7 +1258,7 @@ The following table describes the method arguments:
|
||||
The presence of this annotation is not required since it is, by default, assumed if no
|
||||
other argument is matched.
|
||||
|
||||
You can annotate payload arguments with `@javax.validation.Valid` or Spring's `@Validated`,
|
||||
You can annotate payload arguments with `@jakarta.validation.Valid` or Spring's `@Validated`,
|
||||
to have the payload arguments be automatically validated.
|
||||
|
||||
| `@Header`
|
||||
|
||||
Reference in New Issue
Block a user