Extract recurring asciidoc links to attributes, cleanup old doc files
This commit extract spring-related links and recurring external links into asciidoctor attributes to be used by the Antora toolchain. It notably homogenizes links to: - IETF RFCs - Java Community Process JSRs - the Java API Documentation (on the Java 17 version) - Kotlin documentations (on the Kotlinlang.org version) - the Spring Boot reference guide (on the `html` version) This commit also reworks most link attributes to follow a Project-Category-Misc syntax. For example, `spring-boot-docs` rather than `docs-spring-boot`. Finally, it makes an effort to clean up remainders from the previous documentation toolchain, namely the `docs/asciidoc` folder and `modules/ROOT/pages/attributes.adoc` file. Closes gh-26864 Closes gh-31619
This commit is contained in:
@@ -35,7 +35,7 @@ context"). This section details how you can configure a Spring container (a
|
||||
`WebApplicationContext`) that contains all of the 'business beans' in your application.
|
||||
|
||||
Moving on to specifics, all you need to do is declare a
|
||||
{api-spring-framework}/web/context/ContextLoaderListener.html[`ContextLoaderListener`]
|
||||
{spring-framework-api}/web/context/ContextLoaderListener.html[`ContextLoaderListener`]
|
||||
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.
|
||||
@@ -62,7 +62,7 @@ Further consider the following `<context-param/>` configuration:
|
||||
If you do not specify the `contextConfigLocation` context parameter, the
|
||||
`ContextLoaderListener` looks for a file called `/WEB-INF/applicationContext.xml` to
|
||||
load. Once the context files are loaded, Spring creates a
|
||||
{api-spring-framework}/web/context/WebApplicationContext.html[`WebApplicationContext`]
|
||||
{spring-framework-api}/web/context/WebApplicationContext.html[`WebApplicationContext`]
|
||||
object based on the bean definitions and stores it in the `ServletContext` of the web
|
||||
application.
|
||||
|
||||
@@ -78,7 +78,7 @@ The following example shows how to get the `WebApplicationContext`:
|
||||
----
|
||||
|
||||
The
|
||||
{api-spring-framework}/web/context/support/WebApplicationContextUtils.html[`WebApplicationContextUtils`]
|
||||
{spring-framework-api}/web/context/support/WebApplicationContextUtils.html[`WebApplicationContextUtils`]
|
||||
class is for convenience, so you need not remember the name of the `ServletContext`
|
||||
attribute. Its `getWebApplicationContext()` method returns `null` if an object
|
||||
does not exist under the `WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE`
|
||||
@@ -142,7 +142,7 @@ Configuration-wise, you can define `SpringBeanFacesELResolver` in your JSF
|
||||
|
||||
A custom `ELResolver` works well when mapping your properties to beans in
|
||||
`faces-config.xml`, but, at times, you may need to explicitly grab a bean.
|
||||
The {api-spring-framework}/web/jsf/FacesContextUtils.html[`FacesContextUtils`]
|
||||
The {spring-framework-api}/web/jsf/FacesContextUtils.html[`FacesContextUtils`]
|
||||
class makes this easy. It is similar to `WebApplicationContextUtils`, except that
|
||||
it takes a `FacesContext` parameter rather than a `ServletContext` parameter.
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ rejected. No CORS headers are added to the responses of simple and actual CORS r
|
||||
and, consequently, browsers reject them.
|
||||
|
||||
Each `HandlerMapping` can be
|
||||
{api-spring-framework}/web/reactive/handler/AbstractHandlerMapping.html#setCorsConfigurations-java.util.Map-[configured]
|
||||
{spring-framework-api}/web/reactive/handler/AbstractHandlerMapping.html#setCorsConfigurations-java.util.Map-[configured]
|
||||
individually with URL pattern-based `CorsConfiguration` mappings. In most cases, applications
|
||||
use the WebFlux Java configuration to declare such mappings, which results in a single,
|
||||
global map passed to all `HandlerMapping` implementations.
|
||||
@@ -60,7 +60,7 @@ class- or method-level `@CrossOrigin` annotations (other handlers can implement
|
||||
The rules for combining global and local configuration are generally additive -- for example,
|
||||
all global and all local origins. For those attributes where only a single value can be
|
||||
accepted, such as `allowCredentials` and `maxAge`, the local overrides the global value. See
|
||||
{api-spring-framework}/web/cors/CorsConfiguration.html#combine-org.springframework.web.cors.CorsConfiguration-[`CorsConfiguration#combine(CorsConfiguration)`]
|
||||
{spring-framework-api}/web/cors/CorsConfiguration.html#combine-org.springframework.web.cors.CorsConfiguration-[`CorsConfiguration#combine(CorsConfiguration)`]
|
||||
for more details.
|
||||
|
||||
[TIP]
|
||||
@@ -108,7 +108,7 @@ a finite set of values instead to provide a higher level of security.
|
||||
== `@CrossOrigin`
|
||||
[.small]#xref:web/webmvc-cors.adoc#mvc-cors-controller[See equivalent in the Servlet stack]#
|
||||
|
||||
The {api-spring-framework}/web/bind/annotation/CrossOrigin.html[`@CrossOrigin`]
|
||||
The {spring-framework-api}/web/bind/annotation/CrossOrigin.html[`@CrossOrigin`]
|
||||
annotation enables cross-origin requests on annotated controller methods, as the
|
||||
following example shows:
|
||||
|
||||
@@ -363,7 +363,7 @@ Kotlin::
|
||||
[.small]#xref:web/webmvc-cors.adoc#mvc-cors-filter[See equivalent in the Servlet stack]#
|
||||
|
||||
You can apply CORS support through the built-in
|
||||
{api-spring-framework}/web/cors/reactive/CorsWebFilter.html[`CorsWebFilter`], which is a
|
||||
{spring-framework-api}/web/cors/reactive/CorsWebFilter.html[`CorsWebFilter`], which is a
|
||||
good fit with <<webflux-fn, functional endpoints>>.
|
||||
|
||||
NOTE: If you try to use the `CorsFilter` with Spring Security, keep in mind that Spring
|
||||
|
||||
@@ -122,7 +122,7 @@ Most applications can run through the WebFlux Java configuration, see xref:web/w
|
||||
|
||||
`ServerRequest` and `ServerResponse` are immutable interfaces that offer JDK 8-friendly
|
||||
access to the HTTP request and response.
|
||||
Both request and response provide https://www.reactive-streams.org[Reactive Streams] back pressure
|
||||
Both request and response provide {reactive-streams-site}[Reactive Streams] back pressure
|
||||
against the body streams.
|
||||
The request body is represented with a Reactor `Flux` or `Mono`.
|
||||
The response body is represented with any Reactive Streams `Publisher`, including `Flux` and `Mono`.
|
||||
@@ -350,7 +350,7 @@ ServerResponse.created(location).build()
|
||||
======
|
||||
|
||||
Depending on the codec used, it is possible to pass hint parameters to customize how the
|
||||
body is serialized or deserialized. For example, to specify a https://www.baeldung.com/jackson-json-view-annotation[Jackson JSON view]:
|
||||
body is serialized or deserialized. For example, to specify a {baeldung-blog}/jackson-json-view-annotation[Jackson JSON view]:
|
||||
|
||||
[tabs]
|
||||
======
|
||||
|
||||
@@ -11,7 +11,7 @@ encoding or decoding HTTP messages).
|
||||
|
||||
For annotated controllers, WebFlux transparently adapts to the reactive library chosen by
|
||||
the application. This is done with the help of the
|
||||
{api-spring-framework}/core/ReactiveAdapterRegistry.html[`ReactiveAdapterRegistry`], which
|
||||
{spring-framework-api}/core/ReactiveAdapterRegistry.html[`ReactiveAdapterRegistry`], which
|
||||
provides pluggable support for reactive library and other asynchronous types. The registry
|
||||
has built-in support for RxJava 3, Kotlin coroutines and SmallRye Mutiny, but you can
|
||||
register others, too.
|
||||
|
||||
@@ -209,7 +209,7 @@ sections of the Spring MVC documentation.
|
||||
|
||||
The Spring Framework has a built-in integration for using Spring WebFlux with any
|
||||
templating library that can run on top of the
|
||||
https://www.jcp.org/en/jsr/detail?id=223[JSR-223] Java scripting engine.
|
||||
{JSR}223[JSR-223] Java scripting engine.
|
||||
The following table shows the templating libraries that we have tested on different script engines:
|
||||
|
||||
[%header]
|
||||
@@ -221,7 +221,7 @@ The following table shows the templating libraries that we have tested on differ
|
||||
|https://www.embeddedjs.com/[EJS] |https://openjdk.java.net/projects/nashorn/[Nashorn]
|
||||
|https://www.stuartellis.name/articles/erb/[ERB] |https://www.jruby.org[JRuby]
|
||||
|https://docs.python.org/2/library/string.html#template-strings[String templates] |https://www.jython.org/[Jython]
|
||||
|https://github.com/sdeleuze/kotlin-script-templating[Kotlin Script templating] |https://kotlinlang.org/[Kotlin]
|
||||
|https://github.com/sdeleuze/kotlin-script-templating[Kotlin Script templating] |{kotlin-site}[Kotlin]
|
||||
|===
|
||||
|
||||
TIP: The basic rule for integrating any other script engine is that it must implement the
|
||||
@@ -312,7 +312,7 @@ The `render` function is called with the following parameters:
|
||||
* `String template`: The template content
|
||||
* `Map model`: The view model
|
||||
* `RenderingContext renderingContext`: The
|
||||
{api-spring-framework}/web/servlet/view/script/RenderingContext.html[`RenderingContext`]
|
||||
{spring-framework-api}/web/servlet/view/script/RenderingContext.html[`RenderingContext`]
|
||||
that gives access to the application context, the locale, the template loader, and the
|
||||
URL (since 5.0)
|
||||
|
||||
@@ -404,8 +404,8 @@ The following example shows how compile a template:
|
||||
----
|
||||
|
||||
Check out the Spring Framework unit tests,
|
||||
{spring-framework-main-code}/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/script[Java], and
|
||||
{spring-framework-main-code}/spring-webflux/src/test/resources/org/springframework/web/reactive/result/view/script[resources],
|
||||
{spring-framework-code}/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/script[Java], and
|
||||
{spring-framework-code}/spring-webflux/src/test/resources/org/springframework/web/reactive/result/view/script[resources],
|
||||
for more configuration examples.
|
||||
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ decode request and response content on the server side.
|
||||
`WebClient` needs an HTTP client library to perform requests with. There is built-in
|
||||
support for the following:
|
||||
|
||||
* https://github.com/reactor/reactor-netty[Reactor Netty]
|
||||
* https://docs.oracle.com/en/java/javase/11/docs/api/java.net.http/java/net/http/HttpClient.html[JDK HttpClient]
|
||||
* {reactor-github-org}/reactor-netty[Reactor Netty]
|
||||
* {java-api}/java.net.http/java/net/http/HttpClient.html[JDK HttpClient]
|
||||
* https://github.com/jetty-project/jetty-reactive-httpclient[Jetty Reactive HttpClient]
|
||||
* https://hc.apache.org/index.html[Apache HttpComponents]
|
||||
* Others can be plugged via `ClientHttpConnector`.
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
To test code that uses the `WebClient`, you can use a mock web server, such as the
|
||||
https://github.com/square/okhttp#mockwebserver[OkHttp MockWebServer]. To see an example
|
||||
of its use, check out
|
||||
{spring-framework-main-code}/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java[`WebClientIntegrationTests`]
|
||||
{spring-framework-code}/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java[`WebClientIntegrationTests`]
|
||||
in the Spring Framework test suite or the
|
||||
https://github.com/square/okhttp/tree/master/samples/static-server[`static-server`]
|
||||
sample in the OkHttp repository.
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
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
|
||||
{reactive-streams-site}/[Reactive Streams] back pressure, and runs on such servers as
|
||||
Netty, Undertow, and Servlet containers.
|
||||
|
||||
Both web frameworks mirror the names of their source modules
|
||||
({spring-framework-main-code}/spring-webmvc[spring-webmvc] and
|
||||
{spring-framework-main-code}/spring-webflux[spring-webflux]) and co-exist side by side in the
|
||||
({spring-framework-code}/spring-webmvc[spring-webmvc] and
|
||||
{spring-framework-code}/spring-webflux[spring-webflux]) and co-exist side by side in the
|
||||
Spring Framework. Each module is optional. Applications can use one or the other module or,
|
||||
in some cases, both -- for example, Spring MVC controllers with the reactive `WebClient`.
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
A common requirement for REST services is to include details in the body of error
|
||||
responses. The Spring Framework supports the "Problem Details for HTTP APIs"
|
||||
specification, https://www.rfc-editor.org/rfc/rfc7807.html[RFC 7807].
|
||||
specification, {rfc-site}/rfc7807.html[RFC 7807].
|
||||
|
||||
The following are the main abstractions for this support:
|
||||
|
||||
|
||||
@@ -19,14 +19,14 @@ This section describes the HTTP caching related options available in Spring WebF
|
||||
== `CacheControl`
|
||||
[.small]#xref:web/webmvc/mvc-caching.adoc#mvc-caching-cachecontrol[See equivalent in the Servlet stack]#
|
||||
|
||||
{api-spring-framework}/http/CacheControl.html[`CacheControl`] provides support for
|
||||
{spring-framework-api}/http/CacheControl.html[`CacheControl`] provides support for
|
||||
configuring settings related to the `Cache-Control` header and is accepted as an argument
|
||||
in a number of places:
|
||||
|
||||
* xref:web/webflux/caching.adoc#webflux-caching-etag-lastmodified[Controllers]
|
||||
* xref:web/webflux/caching.adoc#webflux-caching-static-resources[Static Resources]
|
||||
|
||||
While https://tools.ietf.org/html/rfc7234#section-5.2.2[RFC 7234] describes all possible
|
||||
While {rfc-site}/rfc7234#section-5.2.2[RFC 7234] describes all possible
|
||||
directives for the `Cache-Control` response header, the `CacheControl` type takes a
|
||||
use case-oriented approach that focuses on the common scenarios, as the following example shows:
|
||||
|
||||
|
||||
@@ -348,18 +348,18 @@ Kotlin::
|
||||
more readers and writers, customize the default ones, or replace the default ones completely.
|
||||
|
||||
For Jackson JSON and XML, consider using
|
||||
{api-spring-framework}/http/converter/json/Jackson2ObjectMapperBuilder.html[`Jackson2ObjectMapperBuilder`],
|
||||
{spring-framework-api}/http/converter/json/Jackson2ObjectMapperBuilder.html[`Jackson2ObjectMapperBuilder`],
|
||||
which customizes Jackson's default properties with the following ones:
|
||||
|
||||
* https://fasterxml.github.io/jackson-databind/javadoc/2.6/com/fasterxml/jackson/databind/DeserializationFeature.html#FAIL_ON_UNKNOWN_PROPERTIES[`DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES`] is disabled.
|
||||
* https://fasterxml.github.io/jackson-databind/javadoc/2.6/com/fasterxml/jackson/databind/MapperFeature.html#DEFAULT_VIEW_INCLUSION[`MapperFeature.DEFAULT_VIEW_INCLUSION`] is disabled.
|
||||
* {jackson-docs}/jackson-databind/javadoc/2.6/com/fasterxml/jackson/databind/DeserializationFeature.html#FAIL_ON_UNKNOWN_PROPERTIES[`DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES`] is disabled.
|
||||
* {jackson-docs}/jackson-databind/javadoc/2.6/com/fasterxml/jackson/databind/MapperFeature.html#DEFAULT_VIEW_INCLUSION[`MapperFeature.DEFAULT_VIEW_INCLUSION`] is disabled.
|
||||
|
||||
It also automatically registers the following well-known modules if they are detected on the classpath:
|
||||
|
||||
* https://github.com/FasterXML/jackson-datatype-joda[`jackson-datatype-joda`]: Support for Joda-Time types.
|
||||
* https://github.com/FasterXML/jackson-datatype-jsr310[`jackson-datatype-jsr310`]: Support for Java 8 Date and Time API types.
|
||||
* https://github.com/FasterXML/jackson-datatype-jdk8[`jackson-datatype-jdk8`]: Support for other Java 8 types, such as `Optional`.
|
||||
* https://github.com/FasterXML/jackson-module-kotlin[`jackson-module-kotlin`]: Support for Kotlin classes and data classes.
|
||||
* {jackson-github-org}/jackson-datatype-joda[`jackson-datatype-joda`]: Support for Joda-Time types.
|
||||
* {jackson-github-org}/jackson-datatype-jsr310[`jackson-datatype-jsr310`]: Support for Java 8 Date and Time API types.
|
||||
* {jackson-github-org}/jackson-datatype-jdk8[`jackson-datatype-jdk8`]: Support for other Java 8 types, such as `Optional`.
|
||||
* {jackson-github-org}/jackson-module-kotlin[`jackson-module-kotlin`]: Support for Kotlin classes and data classes.
|
||||
|
||||
|
||||
|
||||
@@ -549,7 +549,7 @@ See xref:web/webflux-view.adoc[View Technologies] for more on the view technolog
|
||||
[.small]#xref:web/webmvc/mvc-config/static-resources.adoc[See equivalent in the Servlet stack]#
|
||||
|
||||
This option provides a convenient way to serve static resources from a list of
|
||||
{api-spring-framework}/core/io/Resource.html[`Resource`]-based locations.
|
||||
{spring-framework-api}/core/io/Resource.html[`Resource`]-based locations.
|
||||
|
||||
In the next example, given a request that starts with `/resources`, the relative path is
|
||||
used to find and serve static resources relative to `/static` on the classpath. Resources
|
||||
@@ -598,8 +598,8 @@ Kotlin::
|
||||
See also xref:web/webflux/caching.adoc#webflux-caching-static-resources[HTTP caching support for static resources].
|
||||
|
||||
The resource handler also supports a chain of
|
||||
{api-spring-framework}/web/reactive/resource/ResourceResolver.html[`ResourceResolver`] implementations and
|
||||
{api-spring-framework}/web/reactive/resource/ResourceTransformer.html[`ResourceTransformer`] implementations,
|
||||
{spring-framework-api}/web/reactive/resource/ResourceResolver.html[`ResourceResolver`] implementations and
|
||||
{spring-framework-api}/web/reactive/resource/ResourceTransformer.html[`ResourceTransformer`] implementations,
|
||||
which can be used to create a toolchain for working with optimized resources.
|
||||
|
||||
You can use the `VersionResourceResolver` for versioned resource URLs based on an MD5 hash
|
||||
@@ -685,7 +685,7 @@ for fine-grained control, e.g. last-modified behavior and optimized resource res
|
||||
[.small]#xref:web/webmvc/mvc-config/path-matching.adoc[See equivalent in the Servlet stack]#
|
||||
|
||||
You can customize options related to path matching. For details on the individual options, see the
|
||||
{api-spring-framework}/web/reactive/config/PathMatchConfigurer.html[`PathMatchConfigurer`] javadoc.
|
||||
{spring-framework-api}/web/reactive/config/PathMatchConfigurer.html[`PathMatchConfigurer`] javadoc.
|
||||
The following example shows how to use `PathMatchConfigurer`:
|
||||
|
||||
[tabs]
|
||||
@@ -746,7 +746,7 @@ The WebFlux Java config allows you to customize blocking execution in WebFlux.
|
||||
|
||||
You can have blocking controller methods called on a separate thread by providing
|
||||
an `AsyncTaskExecutor` such as the
|
||||
{api-spring-framework}/core/task/VirtualThreadTaskExecutor.html[`VirtualThreadTaskExecutor`]
|
||||
{spring-framework-api}/core/task/VirtualThreadTaskExecutor.html[`VirtualThreadTaskExecutor`]
|
||||
as follows:
|
||||
|
||||
[tabs]
|
||||
|
||||
@@ -64,6 +64,6 @@ Kotlin::
|
||||
|
||||
The selectors in the preceding example are evaluated at runtime and may negatively impact
|
||||
performance if used extensively. See the
|
||||
{api-spring-framework}/web/bind/annotation/ControllerAdvice.html[`@ControllerAdvice`]
|
||||
{spring-framework-api}/web/bind/annotation/ControllerAdvice.html[`@ControllerAdvice`]
|
||||
javadoc for more details.
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ and others) and is equivalent to `required=false`.
|
||||
| Any other argument
|
||||
| If a method argument is not matched to any of the above, it is, by default, resolved as
|
||||
a `@RequestParam` if it is a simple type, as determined by
|
||||
{api-spring-framework}/beans/BeanUtils.html#isSimpleProperty-java.lang.Class-[BeanUtils#isSimpleProperty],
|
||||
{spring-framework-api}/beans/BeanUtils.html#isSimpleProperty-java.lang.Class-[BeanUtils#isSimpleProperty],
|
||||
or as a `@ModelAttribute`, otherwise.
|
||||
|===
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ Spring offers support for the Jackson JSON library.
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-methods/jackson.adoc[See equivalent in the Servlet stack]#
|
||||
|
||||
Spring WebFlux provides built-in support for
|
||||
https://www.baeldung.com/jackson-json-view-annotation[Jackson's Serialization Views],
|
||||
{baeldung-blog}/jackson-json-view-annotation[Jackson's Serialization Views],
|
||||
which allows rendering only a subset of all fields in an `Object`. To use it with
|
||||
`@ResponseBody` or `ResponseEntity` controller methods, you can use Jackson's
|
||||
`@JsonView` annotation to activate a serialization view class, as the following example shows:
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-methods/matrix-variables.adoc[See equivalent in the Servlet stack]#
|
||||
|
||||
https://tools.ietf.org/html/rfc3986#section-3.3[RFC 3986] discusses name-value pairs in
|
||||
{rfc-site}/rfc3986#section-3.3[RFC 3986] discusses name-value pairs in
|
||||
path segments. In Spring WebFlux, we refer to those as "`matrix variables`" based on an
|
||||
https://www.w3.org/DesignIssues/MatrixURIs.html["`old post`"] by Tim Berners-Lee, but they
|
||||
can be also be referred to as URI path parameters.
|
||||
|
||||
@@ -197,7 +197,7 @@ controller method xref:web/webmvc/mvc-controller/ann-validation.adoc[Validation]
|
||||
|
||||
TIP: Using `@ModelAttribute` is optional. By default, any argument that is not a simple
|
||||
value type as determined by
|
||||
{api-spring-framework}/beans/BeanUtils.html#isSimpleProperty-java.lang.Class-[BeanUtils#isSimpleProperty]
|
||||
{spring-framework-api}/beans/BeanUtils.html#isSimpleProperty-java.lang.Class-[BeanUtils#isSimpleProperty]
|
||||
_AND_ that is not resolved by any other argument resolver is treated as an `@ModelAttribute`.
|
||||
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ When a `@RequestParam` annotation is declared on a `Map<String, String>` or
|
||||
|
||||
Note that use of `@RequestParam` is optional -- for example, to set its attributes. By
|
||||
default, any argument that is a simple value type (as determined by
|
||||
{api-spring-framework}/beans/BeanUtils.html#isSimpleProperty-java.lang.Class-[BeanUtils#isSimpleProperty])
|
||||
{spring-framework-api}/beans/BeanUtils.html#isSimpleProperty-java.lang.Class-[BeanUtils#isSimpleProperty])
|
||||
and is not resolved by any other argument resolver is treated as if it were annotated
|
||||
with `@RequestParam`.
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ generally supported for all return values.
|
||||
| Other return values
|
||||
| If a return value remains unresolved in any other way, it is treated as a model
|
||||
attribute, unless it is a simple type as determined by
|
||||
{api-spring-framework}/beans/BeanUtils.html#isSimpleProperty-java.lang.Class-[BeanUtils#isSimpleProperty],
|
||||
{spring-framework-api}/beans/BeanUtils.html#isSimpleProperty-java.lang.Class-[BeanUtils#isSimpleProperty],
|
||||
in which case it remains unresolved.
|
||||
|===
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ Kotlin::
|
||||
======
|
||||
|
||||
NOTE: When a name is not explicitly specified, a default name is chosen based on the type,
|
||||
as explained in the javadoc for {api-spring-framework}/core/Conventions.html[`Conventions`].
|
||||
as explained in the javadoc for {spring-framework-api}/core/Conventions.html[`Conventions`].
|
||||
You can always assign an explicit name by using the overloaded `addAttribute` method or
|
||||
through the name attribute on `@ModelAttribute` (for a return value).
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ raise `MethodArgumentNotValidException` in case of validation errors. If you wan
|
||||
the errors in the controller method instead, you can declare an `Errors` or `BindingResult`
|
||||
method parameter immediately after the validated parameter.
|
||||
|
||||
Second, if https://beanvalidation.org/[Java Bean Validation] is present _AND_ other method
|
||||
Second, if {bean-validation-site}[Java Bean Validation] is present _AND_ other method
|
||||
parameters, e.g. `@RequestHeader`, `@RequestParam`, `@PathVariable` have `@Constraint`
|
||||
annotations, then method validation is applied to all method arguments, raising
|
||||
`HandlerMethodValidationException` in case of validation errors. You can still declare an
|
||||
|
||||
@@ -12,7 +12,7 @@ This model is flexible and supports diverse workflows.
|
||||
It is also designed to be a Spring bean itself and implements `ApplicationContextAware`
|
||||
for access to the context in which it runs. If `DispatcherHandler` is declared with a bean
|
||||
name of `webHandler`, it is, in turn, discovered by
|
||||
{api-spring-framework}/web/server/adapter/WebHttpHandlerBuilder.html[`WebHttpHandlerBuilder`],
|
||||
{spring-framework-api}/web/server/adapter/WebHttpHandlerBuilder.html[`WebHttpHandlerBuilder`],
|
||||
which puts together a request-processing chain, as described in xref:web/webflux/reactive-spring.adoc#webflux-web-handler-api[`WebHandler` API].
|
||||
|
||||
Spring configuration in a WebFlux application typically contains:
|
||||
@@ -144,9 +144,9 @@ as a `HandlerResult`, along with some additional context, and passed to the firs
|
||||
| 100
|
||||
|
||||
| `ViewResolutionResultHandler`
|
||||
| `CharSequence`, {api-spring-framework}/web/reactive/result/view/View.html[`View`],
|
||||
{api-spring-framework}/ui/Model.html[Model], `Map`,
|
||||
{api-spring-framework}/web/reactive/result/view/Rendering.html[Rendering],
|
||||
| `CharSequence`, {spring-framework-api}/web/reactive/result/view/View.html[`View`],
|
||||
{spring-framework-api}/ui/Model.html[Model], `Map`,
|
||||
{spring-framework-api}/web/reactive/result/view/Rendering.html[Rendering],
|
||||
or any other `Object` is treated as a model attribute.
|
||||
|
||||
See also xref:web/webflux/dispatcher-handler.adoc#webflux-viewresolution[View Resolution].
|
||||
@@ -202,13 +202,13 @@ the list of configured `ViewResolver` implementations.
|
||||
trailing slash, and resolve it to a `View`. The same also happens when a view name
|
||||
was not provided (for example, model attribute was returned) or an async return value
|
||||
(for example, `Mono` completed empty).
|
||||
* {api-spring-framework}/web/reactive/result/view/Rendering.html[Rendering]: API for
|
||||
* {spring-framework-api}/web/reactive/result/view/Rendering.html[Rendering]: API for
|
||||
view resolution scenarios. Explore the options in your IDE with code completion.
|
||||
* `Model`, `Map`: Extra model attributes to be added to the model for the request.
|
||||
* Any other: Any other return value (except for simple types, as determined by
|
||||
{api-spring-framework}/beans/BeanUtils.html#isSimpleProperty-java.lang.Class-[BeanUtils#isSimpleProperty])
|
||||
{spring-framework-api}/beans/BeanUtils.html#isSimpleProperty-java.lang.Class-[BeanUtils#isSimpleProperty])
|
||||
is treated as a model attribute to be added to the model. The attribute name is derived
|
||||
from the class name by using {api-spring-framework}/core/Conventions.html[conventions],
|
||||
from the class name by using {spring-framework-api}/core/Conventions.html[conventions],
|
||||
unless a handler method `@ModelAttribute` annotation is present.
|
||||
|
||||
The model can contain asynchronous, reactive types (for example, from Reactor or RxJava). Prior
|
||||
|
||||
@@ -6,4 +6,4 @@
|
||||
|
||||
HTTP/2 is supported with Reactor Netty, Tomcat, Jetty, and Undertow. However, there are
|
||||
considerations related to server configuration. For more details, see the
|
||||
https://github.com/spring-projects/spring-framework/wiki/HTTP-2-support[HTTP/2 wiki page].
|
||||
{spring-framework-wiki}/HTTP-2-support[HTTP/2 wiki page].
|
||||
|
||||
@@ -38,13 +38,13 @@ code, it becomes important to control the rate of events so that a fast producer
|
||||
overwhelm its destination.
|
||||
|
||||
Reactive Streams is a
|
||||
https://github.com/reactive-streams/reactive-streams-jvm/blob/master/README.md#specification[small spec]
|
||||
(also https://docs.oracle.com/javase/9/docs/api/java/util/concurrent/Flow.html[adopted] in Java 9)
|
||||
{reactive-streams-spec}[small spec]
|
||||
(also {java-api}/java.base/java/util/concurrent/Flow.html[adopted] in Java 9)
|
||||
that defines the interaction between asynchronous components with back pressure.
|
||||
For example a data repository (acting as
|
||||
https://www.reactive-streams.org/reactive-streams-1.0.1-javadoc/org/reactivestreams/Publisher.html[Publisher])
|
||||
{reactive-streams-site}/reactive-streams-1.0.1-javadoc/org/reactivestreams/Publisher.html[Publisher])
|
||||
can produce data that an HTTP server (acting as
|
||||
https://www.reactive-streams.org/reactive-streams-1.0.1-javadoc/org/reactivestreams/Subscriber.html[Subscriber])
|
||||
{reactive-streams-site}/reactive-streams-1.0.1-javadoc/org/reactivestreams/Subscriber.html[Subscriber])
|
||||
can then write to the response. The main purpose of Reactive Streams is to let the
|
||||
subscriber control how quickly or how slowly the publisher produces data.
|
||||
|
||||
@@ -63,10 +63,10 @@ low-level. Applications need a higher-level and richer, functional API to
|
||||
compose async logic -- similar to the Java 8 `Stream` API but not only for collections.
|
||||
This is the role that reactive libraries play.
|
||||
|
||||
https://github.com/reactor/reactor[Reactor] is the reactive library of choice for
|
||||
{reactor-github-org}/reactor[Reactor] is the reactive library of choice for
|
||||
Spring WebFlux. It provides the
|
||||
https://projectreactor.io/docs/core/release/api/reactor/core/publisher/Mono.html[`Mono`] and
|
||||
https://projectreactor.io/docs/core/release/api/reactor/core/publisher/Flux.html[`Flux`] API types
|
||||
{reactor-site}/docs/core/release/api/reactor/core/publisher/Mono.html[`Mono`] and
|
||||
{reactor-site}/docs/core/release/api/reactor/core/publisher/Flux.html[`Flux`] API types
|
||||
to work on data sequences of 0..1 (`Mono`) and 0..N (`Flux`) through a rich set of operators aligned with the
|
||||
ReactiveX https://reactivex.io/documentation/operators.html[vocabulary of operators].
|
||||
Reactor is a Reactive Streams library and, therefore, all of its operators support non-blocking back pressure.
|
||||
|
||||
@@ -13,7 +13,7 @@ request handling, on top of which concrete programming models such as annotated
|
||||
controllers and functional endpoints are built.
|
||||
* For the client side, there is a basic `ClientHttpConnector` contract to perform HTTP
|
||||
requests with non-blocking I/O and Reactive Streams back pressure, along with adapters for
|
||||
https://github.com/reactor/reactor-netty[Reactor Netty], reactive
|
||||
{reactor-github-org}/reactor-netty[Reactor Netty], reactive
|
||||
https://github.com/jetty-project/jetty-reactive-httpclient[Jetty HttpClient]
|
||||
and https://hc.apache.org/[Apache HttpComponents].
|
||||
The higher level xref:web/webflux-webclient.adoc[WebClient] used in applications
|
||||
@@ -26,7 +26,7 @@ deserialization of HTTP request and response content.
|
||||
[[webflux-httphandler]]
|
||||
== `HttpHandler`
|
||||
|
||||
{api-spring-framework}/http/server/reactive/HttpHandler.html[HttpHandler]
|
||||
{spring-framework-api}/http/server/reactive/HttpHandler.html[HttpHandler]
|
||||
is a simple contract with a single method to handle a request and a response. It is
|
||||
intentionally minimal, and its main and only purpose is to be a minimal abstraction
|
||||
over different HTTP server APIs.
|
||||
@@ -39,7 +39,7 @@ The following table describes the supported server APIs:
|
||||
|
||||
| Netty
|
||||
| Netty API
|
||||
| https://github.com/reactor/reactor-netty[Reactor Netty]
|
||||
| {reactor-github-org}/reactor-netty[Reactor Netty]
|
||||
|
||||
| Undertow
|
||||
| Undertow API
|
||||
@@ -59,7 +59,7 @@ The following table describes the supported server APIs:
|
||||
|===
|
||||
|
||||
The following table describes server dependencies (also see
|
||||
https://github.com/spring-projects/spring-framework/wiki/What%27s-New-in-the-Spring-Framework[supported versions]):
|
||||
{spring-framework-wiki}/What%27s-New-in-the-Spring-Framework[supported versions]):
|
||||
|
||||
|===
|
||||
|Server name|Group id|Artifact name
|
||||
@@ -213,7 +213,7 @@ Kotlin::
|
||||
*Servlet Container*
|
||||
|
||||
To deploy as a WAR to any Servlet container, you can extend and include
|
||||
{api-spring-framework}/web/server/adapter/AbstractReactiveWebInitializer.html[`AbstractReactiveWebInitializer`]
|
||||
{spring-framework-api}/web/server/adapter/AbstractReactiveWebInitializer.html[`AbstractReactiveWebInitializer`]
|
||||
in the WAR. That class wraps an `HttpHandler` with `ServletHttpHandlerAdapter` and registers
|
||||
that as a `Servlet`.
|
||||
|
||||
@@ -224,9 +224,9 @@ that as a `Servlet`.
|
||||
|
||||
The `org.springframework.web.server` package builds on the xref:web/webflux/reactive-spring.adoc#webflux-httphandler[`HttpHandler`] contract
|
||||
to provide a general-purpose web API for processing requests through a chain of multiple
|
||||
{api-spring-framework}/web/server/WebExceptionHandler.html[`WebExceptionHandler`], multiple
|
||||
{api-spring-framework}/web/server/WebFilter.html[`WebFilter`], and a single
|
||||
{api-spring-framework}/web/server/WebHandler.html[`WebHandler`] component. The chain can
|
||||
{spring-framework-api}/web/server/WebExceptionHandler.html[`WebExceptionHandler`], multiple
|
||||
{spring-framework-api}/web/server/WebFilter.html[`WebFilter`], and a single
|
||||
{spring-framework-api}/web/server/WebHandler.html[`WebHandler`] component. The chain can
|
||||
be put together with `WebHttpHandlerBuilder` by simply pointing to a Spring
|
||||
`ApplicationContext` where components are
|
||||
xref:web/webflux/reactive-spring.adoc#webflux-web-handler-api-special-beans[auto-detected], and/or by registering components
|
||||
@@ -438,7 +438,7 @@ The following table describes the available `WebExceptionHandler` implementation
|
||||
|
||||
| `ResponseStatusExceptionHandler`
|
||||
| Provides handling for exceptions of type
|
||||
{api-spring-framework}/web/server/ResponseStatusException.html[`ResponseStatusException`]
|
||||
{spring-framework-api}/web/server/ResponseStatusException.html[`ResponseStatusException`]
|
||||
by setting the response to the HTTP status code of the exception.
|
||||
|
||||
| `WebFluxResponseStatusExceptionHandler`
|
||||
@@ -459,15 +459,15 @@ The `spring-web` and `spring-core` modules provide support for serializing and
|
||||
deserializing byte content to and from higher level objects through non-blocking I/O with
|
||||
Reactive Streams back pressure. The following describes this support:
|
||||
|
||||
* {api-spring-framework}/core/codec/Encoder.html[`Encoder`] and
|
||||
{api-spring-framework}/core/codec/Decoder.html[`Decoder`] are low level contracts to
|
||||
* {spring-framework-api}/core/codec/Encoder.html[`Encoder`] and
|
||||
{spring-framework-api}/core/codec/Decoder.html[`Decoder`] are low level contracts to
|
||||
encode and decode content independent of HTTP.
|
||||
* {api-spring-framework}/http/codec/HttpMessageReader.html[`HttpMessageReader`] and
|
||||
{api-spring-framework}/http/codec/HttpMessageWriter.html[`HttpMessageWriter`] are contracts
|
||||
* {spring-framework-api}/http/codec/HttpMessageReader.html[`HttpMessageReader`] and
|
||||
{spring-framework-api}/http/codec/HttpMessageWriter.html[`HttpMessageWriter`] are contracts
|
||||
to encode and decode HTTP message content.
|
||||
* An `Encoder` can be wrapped with `EncoderHttpMessageWriter` to adapt it for use in a web
|
||||
application, while a `Decoder` can be wrapped with `DecoderHttpMessageReader`.
|
||||
* {api-spring-framework}/core/io/buffer/DataBuffer.html[`DataBuffer`] abstracts different
|
||||
* {spring-framework-api}/core/io/buffer/DataBuffer.html[`DataBuffer`] abstracts different
|
||||
byte buffer representations (e.g. Netty `ByteBuf`, `java.nio.ByteBuffer`, etc.) and is
|
||||
what all codecs work on. See xref:core/databuffer-codec.adoc[Data Buffers and Codecs] in the
|
||||
"Spring Core" section for more on this topic.
|
||||
@@ -485,7 +485,7 @@ xref:web/webflux/config.adoc#webflux-config-message-codecs[HTTP message codecs].
|
||||
[[webflux-codecs-jackson]]
|
||||
=== Jackson JSON
|
||||
|
||||
JSON and binary JSON (https://github.com/FasterXML/smile-format-specification[Smile]) are
|
||||
JSON and binary JSON ({jackson-github-org}/smile-format-specification[Smile]) are
|
||||
both supported when the Jackson library is present.
|
||||
|
||||
The `Jackson2Decoder` works as follows:
|
||||
@@ -549,7 +549,7 @@ for the actual parsing to a `Flux<Part>` and then simply collects the parts into
|
||||
By default, the `DefaultPartHttpMessageReader` is used, but this can be changed through the
|
||||
`ServerCodecConfigurer`.
|
||||
For more information about the `DefaultPartHttpMessageReader`, refer to the
|
||||
{api-spring-framework}/http/codec/multipart/DefaultPartHttpMessageReader.html[javadoc of `DefaultPartHttpMessageReader`].
|
||||
{spring-framework-api}/http/codec/multipart/DefaultPartHttpMessageReader.html[javadoc of `DefaultPartHttpMessageReader`].
|
||||
|
||||
On the server side where multipart form content may need to be accessed from multiple
|
||||
places, `ServerWebExchange` provides a dedicated `getMultipartData()` method that parses
|
||||
@@ -643,11 +643,11 @@ is not useful for correlating log messages that belong to a specific request. Th
|
||||
WebFlux log messages are prefixed with a request-specific ID by default.
|
||||
|
||||
On the server side, the log ID is stored in the `ServerWebExchange` attribute
|
||||
({api-spring-framework}/web/server/ServerWebExchange.html#LOG_ID_ATTRIBUTE[`LOG_ID_ATTRIBUTE`]),
|
||||
({spring-framework-api}/web/server/ServerWebExchange.html#LOG_ID_ATTRIBUTE[`LOG_ID_ATTRIBUTE`]),
|
||||
while a fully formatted prefix based on that ID is available from
|
||||
`ServerWebExchange#getLogPrefix()`. On the `WebClient` side, the log ID is stored in the
|
||||
`ClientRequest` attribute
|
||||
({api-spring-framework}/web/reactive/function/client/ClientRequest.html#LOG_ID_ATTRIBUTE[`LOG_ID_ATTRIBUTE`])
|
||||
({spring-framework-api}/web/reactive/function/client/ClientRequest.html#LOG_ID_ATTRIBUTE[`LOG_ID_ATTRIBUTE`])
|
||||
,while a fully formatted prefix is available from `ClientRequest#logPrefix()`.
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
[.small]#xref:web/webmvc/mvc-security.adoc[See equivalent in the Servlet stack]#
|
||||
|
||||
The https://spring.io/projects/spring-security[Spring Security] project provides support
|
||||
The {spring-site-projects}/spring-security[Spring Security] project provides support
|
||||
for protecting web applications from malicious exploits. See the Spring Security
|
||||
reference documentation, including:
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ rejected. No CORS headers are added to the responses of simple and actual CORS r
|
||||
and, consequently, browsers reject them.
|
||||
|
||||
Each `HandlerMapping` can be
|
||||
{api-spring-framework}/web/servlet/handler/AbstractHandlerMapping.html#setCorsConfigurations-java.util.Map-[configured]
|
||||
{spring-framework-api}/web/servlet/handler/AbstractHandlerMapping.html#setCorsConfigurations-java.util.Map-[configured]
|
||||
individually with URL pattern-based `CorsConfiguration` mappings. In most cases, applications
|
||||
use the MVC Java configuration or the XML namespace to declare such mappings, which results
|
||||
in a single global map being passed to all `HandlerMapping` instances.
|
||||
@@ -89,7 +89,7 @@ class- or method-level `@CrossOrigin` annotations (other handlers can implement
|
||||
The rules for combining global and local configuration are generally additive -- for example,
|
||||
all global and all local origins. For those attributes where only a single value can be
|
||||
accepted, e.g. `allowCredentials` and `maxAge`, the local overrides the global value. See
|
||||
{api-spring-framework}/web/cors/CorsConfiguration.html#combine-org.springframework.web.cors.CorsConfiguration-[`CorsConfiguration#combine(CorsConfiguration)`]
|
||||
{spring-framework-api}/web/cors/CorsConfiguration.html#combine-org.springframework.web.cors.CorsConfiguration-[`CorsConfiguration#combine(CorsConfiguration)`]
|
||||
for more details.
|
||||
|
||||
[TIP]
|
||||
@@ -108,7 +108,7 @@ To learn more from the source or make advanced customizations, check the code be
|
||||
== `@CrossOrigin`
|
||||
[.small]#xref:web/webflux-cors.adoc#webflux-cors-controller[See equivalent in the Reactive stack]#
|
||||
|
||||
The {api-spring-framework}/web/bind/annotation/CrossOrigin.html[`@CrossOrigin`]
|
||||
The {spring-framework-api}/web/bind/annotation/CrossOrigin.html[`@CrossOrigin`]
|
||||
annotation enables cross-origin requests on annotated controller methods,
|
||||
as the following example shows:
|
||||
|
||||
@@ -385,7 +385,7 @@ as the following example shows:
|
||||
[.small]#xref:web/webflux-cors.adoc#webflux-cors-webfilter[See equivalent in the Reactive stack]#
|
||||
|
||||
You can apply CORS support through the built-in
|
||||
{api-spring-framework}/web/filter/CorsFilter.html[`CorsFilter`].
|
||||
{spring-framework-api}/web/filter/CorsFilter.html[`CorsFilter`].
|
||||
|
||||
NOTE: If you try to use the `CorsFilter` with Spring Security, keep in mind that Spring
|
||||
Security has {docs-spring-security}/servlet/integrations/cors.html[built-in support] for
|
||||
|
||||
@@ -102,7 +102,7 @@ cookies or other HTTP headers. The feed is automatically written to the response
|
||||
object after the method returns.
|
||||
|
||||
For an example of creating an Atom view, see Alef Arendsen's Spring Team Blog
|
||||
https://spring.io/blog/2009/03/16/adding-an-atom-view-to-an-application-using-spring-s-rest-support[entry].
|
||||
{spring-site-blog}/2009/03/16/adding-an-atom-view-to-an-application-using-spring-s-rest-support[entry].
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ serializers and deserializers for specific types.
|
||||
[.small]#xref:web/webflux-view.adoc#webflux-view-httpmessagewriter[See equivalent in the Reactive stack]#
|
||||
|
||||
`MappingJackson2XmlView` uses the
|
||||
https://github.com/FasterXML/jackson-dataformat-xml[Jackson XML extension's] `XmlMapper`
|
||||
{jackson-github-org}/jackson-dataformat-xml[Jackson XML extension's] `XmlMapper`
|
||||
to render the response content as XML. If the model contains multiple entries, you should
|
||||
explicitly set the object to be serialized by using the `modelKey` bean property. If the
|
||||
model contains a single entry, it is serialized automatically.
|
||||
|
||||
@@ -44,7 +44,7 @@ Spring tags have HTML escaping features to enable or disable escaping of charact
|
||||
|
||||
The `spring.tld` tag library descriptor (TLD) is included in the `spring-webmvc.jar`.
|
||||
For a comprehensive reference on individual tags, browse the
|
||||
{api-spring-framework}/web/servlet/tags/package-summary.html#package.description[API reference]
|
||||
{spring-framework-api}/web/servlet/tags/package-summary.html#package.description[API reference]
|
||||
or see the tag library description.
|
||||
|
||||
|
||||
@@ -745,7 +745,7 @@ The HTML would be as follows:
|
||||
|
||||
The `spring-form.tld` tag library descriptor (TLD) is included in the `spring-webmvc.jar`.
|
||||
For a comprehensive reference on individual tags, browse the
|
||||
{api-spring-framework}/web/servlet/tags/form/package-summary.html#package.description[API reference]
|
||||
{spring-framework-api}/web/servlet/tags/form/package-summary.html#package.description[API reference]
|
||||
or see the tag library description.
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
The Spring Framework has a built-in integration for using Spring MVC with any
|
||||
templating library that can run on top of the
|
||||
https://www.jcp.org/en/jsr/detail?id=223[JSR-223] Java scripting engine. We have tested the following
|
||||
{JSR}223[JSR-223] Java scripting engine. We have tested the following
|
||||
templating libraries on different script engines:
|
||||
|
||||
[%header]
|
||||
@@ -17,7 +17,7 @@ templating libraries on different script engines:
|
||||
|https://www.embeddedjs.com/[EJS] |https://openjdk.java.net/projects/nashorn/[Nashorn]
|
||||
|https://www.stuartellis.name/articles/erb/[ERB] |https://www.jruby.org[JRuby]
|
||||
|https://docs.python.org/2/library/string.html#template-strings[String templates] |https://www.jython.org/[Jython]
|
||||
|https://github.com/sdeleuze/kotlin-script-templating[Kotlin Script templating] |https://kotlinlang.org/[Kotlin]
|
||||
|https://github.com/sdeleuze/kotlin-script-templating[Kotlin Script templating] |{kotlin-site}[Kotlin]
|
||||
|===
|
||||
|
||||
TIP: The basic rule for integrating any other script engine is that it must implement the
|
||||
@@ -174,7 +174,7 @@ The render function is called with the following parameters:
|
||||
* `String template`: The template content
|
||||
* `Map model`: The view model
|
||||
* `RenderingContext renderingContext`: The
|
||||
{api-spring-framework}/web/servlet/view/script/RenderingContext.html[`RenderingContext`]
|
||||
{spring-framework-api}/web/servlet/view/script/RenderingContext.html[`RenderingContext`]
|
||||
that gives access to the application context, the locale, the template loader, and the
|
||||
URL (since 5.0)
|
||||
|
||||
@@ -265,8 +265,8 @@ template engine configuration, for example). The following example shows how to
|
||||
----
|
||||
|
||||
Check out the Spring Framework unit tests,
|
||||
{spring-framework-main-code}/spring-webmvc/src/test/java/org/springframework/web/servlet/view/script[Java], and
|
||||
{spring-framework-main-code}/spring-webmvc/src/test/resources/org/springframework/web/servlet/view/script[resources],
|
||||
{spring-framework-code}/spring-webmvc/src/test/java/org/springframework/web/servlet/view/script[Java], and
|
||||
{spring-framework-code}/spring-webmvc/src/test/resources/org/springframework/web/servlet/view/script[resources],
|
||||
for more configuration examples.
|
||||
|
||||
|
||||
|
||||
@@ -7,16 +7,16 @@
|
||||
Spring Web MVC is the original web framework built on the Servlet API and has been included
|
||||
in the Spring Framework from the very beginning. The formal name, "Spring Web MVC,"
|
||||
comes from the name of its source module
|
||||
({spring-framework-main-code}/spring-webmvc[`spring-webmvc`]),
|
||||
({spring-framework-code}/spring-webmvc[`spring-webmvc`]),
|
||||
but it is more commonly known as "Spring MVC".
|
||||
|
||||
Parallel to Spring Web MVC, Spring Framework 5.0 introduced a reactive-stack web framework
|
||||
whose name, "Spring WebFlux," is also based on its source module
|
||||
({spring-framework-main-code}/spring-webflux[`spring-webflux`]).
|
||||
({spring-framework-code}/spring-webflux[`spring-webflux`]).
|
||||
This chapter covers Spring Web MVC. For reactive-stack web applications, see
|
||||
xref:web-reactive.adoc[Web on Reactive Stack].
|
||||
|
||||
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].
|
||||
{spring-framework-wiki}/Spring-Framework-Versions[Wiki].
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ See xref:web/webmvc/mvc-caching.adoc[HTTP Caching].
|
||||
|
||||
This filter has a `writeWeakETag` parameter that configures the filter to write weak ETags
|
||||
similar to the following: `W/"02a2d595e6ed9a0b24f027f2b63b134d6"` (as defined in
|
||||
https://tools.ietf.org/html/rfc7232#section-2.3[RFC 7232 Section 2.3]).
|
||||
{rfc-site}/rfc7232#section-2.3[RFC 7232 Section 2.3]).
|
||||
|
||||
In order to support xref:web/webmvc/mvc-ann-async.adoc[asynchronous requests] this filter must be mapped
|
||||
with `DispatcherType.ASYNC` so that the filter can delay and successfully generate an
|
||||
|
||||
@@ -137,7 +137,7 @@ Here is a very concise overview of Servlet asynchronous request processing:
|
||||
asynchronously produced return value from the `Callable`.
|
||||
|
||||
For further background and context, you can also read
|
||||
https://spring.io/blog/2012/05/07/spring-mvc-3-2-preview-introducing-servlet-3-async-support[the
|
||||
{spring-site-blog}/2012/05/07/spring-mvc-3-2-preview-introducing-servlet-3-async-support[the
|
||||
blog posts] that introduced asynchronous request processing support in Spring MVC 3.2.
|
||||
|
||||
|
||||
@@ -165,11 +165,11 @@ processing (instead of `postHandle` and `afterCompletion`).
|
||||
`HandlerInterceptor` implementations can also register a `CallableProcessingInterceptor`
|
||||
or a `DeferredResultProcessingInterceptor`, to integrate more deeply with the
|
||||
lifecycle of an asynchronous request (for example, to handle a timeout event). See
|
||||
{api-spring-framework}/web/servlet/AsyncHandlerInterceptor.html[`AsyncHandlerInterceptor`]
|
||||
{spring-framework-api}/web/servlet/AsyncHandlerInterceptor.html[`AsyncHandlerInterceptor`]
|
||||
for more details.
|
||||
|
||||
`DeferredResult` provides `onTimeout(Runnable)` and `onCompletion(Runnable)` callbacks.
|
||||
See the {api-spring-framework}/web/context/request/async/DeferredResult.html[javadoc of `DeferredResult`]
|
||||
See the {spring-framework-api}/web/context/request/async/DeferredResult.html[javadoc of `DeferredResult`]
|
||||
for more details. `Callable` can be substituted for `WebAsyncTask` that exposes additional
|
||||
methods for timeout and completion callbacks.
|
||||
|
||||
@@ -399,7 +399,7 @@ Applications can also return `Flux<ServerSentEvent>` or `Observable<ServerSentEv
|
||||
to, similar to using `DeferredResult<List<?>>`.
|
||||
|
||||
TIP: Spring MVC supports Reactor and RxJava through the
|
||||
{api-spring-framework}/core/ReactiveAdapterRegistry.html[`ReactiveAdapterRegistry`] from
|
||||
{spring-framework-api}/core/ReactiveAdapterRegistry.html[`ReactiveAdapterRegistry`] from
|
||||
`spring-core`, which lets it adapt from multiple reactive libraries.
|
||||
|
||||
For streaming to the response, reactive back pressure is supported, but writes to the
|
||||
@@ -420,7 +420,7 @@ across multiple threads. The Micrometer
|
||||
https://github.com/micrometer-metrics/context-propagation#context-propagation-library[Context Propagation]
|
||||
library simplifies context propagation across threads, and across context mechanisms such
|
||||
as `ThreadLocal` values,
|
||||
Reactor https://projectreactor.io/docs/core/release/reference/#context[context],
|
||||
Reactor {reactor-site}/docs/core/release/reference/#context[context],
|
||||
GraphQL Java https://www.graphql-java.com/documentation/concerns/#context-objects[context],
|
||||
and others.
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
A common requirement for REST services is to include details in the body of error
|
||||
responses. The Spring Framework supports the "Problem Details for HTTP APIs"
|
||||
specification, https://www.rfc-editor.org/rfc/rfc7807.html[RFC 7807].
|
||||
specification, {rfc-site}/rfc7807[RFC 7807].
|
||||
|
||||
The following are the main abstractions for this support:
|
||||
|
||||
|
||||
@@ -19,16 +19,16 @@ This section describes the HTTP caching-related options that are available in Sp
|
||||
== `CacheControl`
|
||||
[.small]#xref:web/webflux/caching.adoc#webflux-caching-cachecontrol[See equivalent in the Reactive stack]#
|
||||
|
||||
{api-spring-framework}/http/CacheControl.html[`CacheControl`] provides support for
|
||||
{spring-framework-api}/http/CacheControl.html[`CacheControl`] provides support for
|
||||
configuring settings related to the `Cache-Control` header and is accepted as an argument
|
||||
in a number of places:
|
||||
|
||||
* {api-spring-framework}/web/servlet/mvc/WebContentInterceptor.html[`WebContentInterceptor`]
|
||||
* {api-spring-framework}/web/servlet/support/WebContentGenerator.html[`WebContentGenerator`]
|
||||
* {spring-framework-api}/web/servlet/mvc/WebContentInterceptor.html[`WebContentInterceptor`]
|
||||
* {spring-framework-api}/web/servlet/support/WebContentGenerator.html[`WebContentGenerator`]
|
||||
* xref:web/webmvc/mvc-caching.adoc#mvc-caching-etag-lastmodified[Controllers]
|
||||
* xref:web/webmvc/mvc-caching.adoc#mvc-caching-static-resources[Static Resources]
|
||||
|
||||
While https://tools.ietf.org/html/rfc7234#section-5.2.2[RFC 7234] describes all possible
|
||||
While {rfc-site}/rfc7234#section-5.2.2[RFC 7234] describes all possible
|
||||
directives for the `Cache-Control` response header, the `CacheControl` type takes a
|
||||
use case-oriented approach that focuses on the common scenarios:
|
||||
|
||||
|
||||
@@ -5,14 +5,13 @@
|
||||
|
||||
You can set the `HttpMessageConverter` instances to use in Java configuration,
|
||||
replacing the ones used by default, by overriding
|
||||
{api-spring-framework}/web/servlet/config/annotation/WebMvcConfigurer.html#configureMessageConverters-java.util.List-[`configureMessageConverters()`].
|
||||
{spring-framework-api}/web/servlet/config/annotation/WebMvcConfigurer.html#configureMessageConverters-java.util.List-[`configureMessageConverters()`].
|
||||
You can also customize the list of configured message converters at the end by overriding
|
||||
{api-spring-framework}/web/servlet/config/annotation/WebMvcConfigurer.html#extendMessageConverters-java.util.List-[`extendMessageConverters()`].
|
||||
{spring-framework-api}/web/servlet/config/annotation/WebMvcConfigurer.html#extendMessageConverters-java.util.List-[`extendMessageConverters()`].
|
||||
|
||||
TIP: In a Spring Boot application, the `WebMvcAutoConfiguration` adds any
|
||||
`HttpMessageConverter` beans it detects, in addition to default converters. Hence, in a
|
||||
Boot application, prefer to use the
|
||||
https://docs.spring.io/spring-framework/reference/web/webmvc/mvc-config/message-converters.html[HttpMessageConverters]
|
||||
Boot application, prefer to use the {spring-boot-docs}/web.html#web.servlet.spring-mvc.message-converters[HttpMessageConverters]
|
||||
mechanism. Or alternatively, use `extendMessageConverters` to modify message converters
|
||||
at the end.
|
||||
|
||||
@@ -60,24 +59,24 @@ Kotlin::
|
||||
======
|
||||
|
||||
In the preceding example,
|
||||
{api-spring-framework}/http/converter/json/Jackson2ObjectMapperBuilder.html[`Jackson2ObjectMapperBuilder`]
|
||||
{spring-framework-api}/http/converter/json/Jackson2ObjectMapperBuilder.html[`Jackson2ObjectMapperBuilder`]
|
||||
is used to create a common configuration for both `MappingJackson2HttpMessageConverter` and
|
||||
`MappingJackson2XmlHttpMessageConverter` with indentation enabled, a customized date format,
|
||||
and the registration of
|
||||
https://github.com/FasterXML/jackson-module-parameter-names[`jackson-module-parameter-names`],
|
||||
{jackson-github-org}/jackson-module-parameter-names[`jackson-module-parameter-names`],
|
||||
Which adds support for accessing parameter names (a feature added in Java 8).
|
||||
|
||||
This builder customizes Jackson's default properties as follows:
|
||||
|
||||
* https://fasterxml.github.io/jackson-databind/javadoc/2.6/com/fasterxml/jackson/databind/DeserializationFeature.html#FAIL_ON_UNKNOWN_PROPERTIES[`DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES`] is disabled.
|
||||
* https://fasterxml.github.io/jackson-databind/javadoc/2.6/com/fasterxml/jackson/databind/MapperFeature.html#DEFAULT_VIEW_INCLUSION[`MapperFeature.DEFAULT_VIEW_INCLUSION`] is disabled.
|
||||
* {jackson-docs}/jackson-databind/javadoc/2.6/com/fasterxml/jackson/databind/DeserializationFeature.html#FAIL_ON_UNKNOWN_PROPERTIES[`DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES`] is disabled.
|
||||
* {jackson-docs}/jackson-databind/javadoc/2.6/com/fasterxml/jackson/databind/MapperFeature.html#DEFAULT_VIEW_INCLUSION[`MapperFeature.DEFAULT_VIEW_INCLUSION`] is disabled.
|
||||
|
||||
It also automatically registers the following well-known modules if they are detected on the classpath:
|
||||
|
||||
* https://github.com/FasterXML/jackson-datatype-joda[jackson-datatype-joda]: Support for Joda-Time types.
|
||||
* https://github.com/FasterXML/jackson-datatype-jsr310[jackson-datatype-jsr310]: Support for Java 8 Date and Time API types.
|
||||
* https://github.com/FasterXML/jackson-datatype-jdk8[jackson-datatype-jdk8]: Support for other Java 8 types, such as `Optional`.
|
||||
* https://github.com/FasterXML/jackson-module-kotlin[`jackson-module-kotlin`]: Support for Kotlin classes and data classes.
|
||||
* {jackson-github-org}/jackson-datatype-joda[jackson-datatype-joda]: Support for Joda-Time types.
|
||||
* {jackson-github-org}/jackson-datatype-jsr310[jackson-datatype-jsr310]: Support for Java 8 Date and Time API types.
|
||||
* {jackson-github-org}/jackson-datatype-jdk8[jackson-datatype-jdk8]: Support for other Java 8 types, such as `Optional`.
|
||||
* {jackson-github-org}/jackson-module-kotlin[`jackson-module-kotlin`]: Support for Kotlin classes and data classes.
|
||||
|
||||
NOTE: Enabling indentation with Jackson XML support requires
|
||||
https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.codehaus.woodstox%22%20AND%20a%3A%22woodstox-core-asl%22[`woodstox-core-asl`]
|
||||
@@ -86,7 +85,7 @@ dependency in addition to https://search.maven.org/#search%7Cga%7C1%7Ca%3A%22jac
|
||||
Other interesting Jackson modules are available:
|
||||
|
||||
* https://github.com/zalando/jackson-datatype-money[jackson-datatype-money]: Support for `javax.money` types (unofficial module).
|
||||
* https://github.com/FasterXML/jackson-datatype-hibernate[jackson-datatype-hibernate]: Support for Hibernate-specific types and properties (including lazy-loading aspects).
|
||||
* {jackson-github-org}/jackson-datatype-hibernate[jackson-datatype-hibernate]: Support for Hibernate-specific types and properties (including lazy-loading aspects).
|
||||
|
||||
The following example shows how to achieve the same configuration in XML:
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
You can customize options related to path matching and treatment of the URL.
|
||||
For details on the individual options, see the
|
||||
{api-spring-framework}/web/servlet/config/annotation/PathMatchConfigurer.html[`PathMatchConfigurer`] javadoc.
|
||||
{spring-framework-api}/web/servlet/config/annotation/PathMatchConfigurer.html[`PathMatchConfigurer`] javadoc.
|
||||
|
||||
The following example shows how to customize path matching in Java configuration:
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
[.small]#xref:web/webflux/config.adoc#webflux-config-static-resources[See equivalent in the Reactive stack]#
|
||||
|
||||
This option provides a convenient way to serve static resources from a list of
|
||||
{api-spring-framework}/core/io/Resource.html[`Resource`]-based locations.
|
||||
{spring-framework-api}/core/io/Resource.html[`Resource`]-based locations.
|
||||
|
||||
In the next example, given a request that starts with `/resources`, the relative path is
|
||||
used to find and serve static resources relative to `/public` under the web application
|
||||
@@ -64,8 +64,8 @@ See also
|
||||
xref:web/webmvc/mvc-caching.adoc#mvc-caching-static-resources[HTTP caching support for static resources].
|
||||
|
||||
The resource handler also supports a chain of
|
||||
{api-spring-framework}/web/servlet/resource/ResourceResolver.html[`ResourceResolver`] implementations and
|
||||
{api-spring-framework}/web/servlet/resource/ResourceTransformer.html[`ResourceTransformer`] implementations,
|
||||
{spring-framework-api}/web/servlet/resource/ResourceResolver.html[`ResourceResolver`] implementations and
|
||||
{spring-framework-api}/web/servlet/resource/ResourceTransformer.html[`ResourceTransformer`] implementations,
|
||||
which you can use to create a toolchain for working with optimized resources.
|
||||
|
||||
You can use the `VersionResourceResolver` for versioned resource URLs based on an MD5 hash
|
||||
|
||||
@@ -47,7 +47,7 @@ Kotlin::
|
||||
In the preceding example, the method accepts a `Model` and returns a view name as a `String`,
|
||||
but many other options exist and are explained later in this chapter.
|
||||
|
||||
TIP: Guides and tutorials on https://spring.io/guides[spring.io] use the annotation-based
|
||||
TIP: Guides and tutorials on {spring-site-guides}[spring.io] use the annotation-based
|
||||
programming model described in this section.
|
||||
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ Kotlin::
|
||||
|
||||
The selectors in the preceding example are evaluated at runtime and may negatively impact
|
||||
performance if used extensively. See the
|
||||
{api-spring-framework}/web/bind/annotation/ControllerAdvice.html[`@ControllerAdvice`]
|
||||
{spring-framework-api}/web/bind/annotation/ControllerAdvice.html[`@ControllerAdvice`]
|
||||
javadoc for more details.
|
||||
|
||||
|
||||
|
||||
@@ -271,7 +271,7 @@ see xref:web/webmvc/mvc-ann-rest-exceptions.adoc[Error Responses]
|
||||
|
||||
| Any other return value
|
||||
| If a return value is not matched to any of the above and is not a simple type (as determined by
|
||||
{api-spring-framework}/beans/BeanUtils.html#isSimpleProperty-java.lang.Class-[BeanUtils#isSimpleProperty]),
|
||||
{spring-framework-api}/beans/BeanUtils.html#isSimpleProperty-java.lang.Class-[BeanUtils#isSimpleProperty]),
|
||||
by default, it is treated as a model attribute to be added to the model. If it is a simple type,
|
||||
it remains unresolved.
|
||||
|===
|
||||
|
||||
@@ -135,7 +135,7 @@ and others) and is equivalent to `required=false`.
|
||||
| Any other argument
|
||||
| If a method argument is not matched to any of the earlier values in this table and it is
|
||||
a simple type (as determined by
|
||||
{api-spring-framework}/beans/BeanUtils.html#isSimpleProperty-java.lang.Class-[BeanUtils#isSimpleProperty]),
|
||||
{spring-framework-api}/beans/BeanUtils.html#isSimpleProperty-java.lang.Class-[BeanUtils#isSimpleProperty]),
|
||||
it is resolved as a `@RequestParam`. Otherwise, it is resolved as a `@ModelAttribute`.
|
||||
|===
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ Spring offers support for the Jackson JSON library.
|
||||
[.small]#xref:web/webflux/controller/ann-methods/jackson.adoc#webflux-ann-jsonview[See equivalent in the Reactive stack]#
|
||||
|
||||
Spring MVC provides built-in support for
|
||||
https://www.baeldung.com/jackson-json-view-annotation[Jackson's Serialization Views],
|
||||
{baeldung-blog}/jackson-json-view-annotation[Jackson's Serialization Views],
|
||||
which allow rendering only a subset of all fields in an `Object`. To use it with
|
||||
`@ResponseBody` or `ResponseEntity` controller methods, you can use Jackson's
|
||||
`@JsonView` annotation to activate a serialization view class, as the following example shows:
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
[.small]#xref:web/webflux/controller/ann-methods/matrix-variables.adoc[See equivalent in the Reactive stack]#
|
||||
|
||||
https://tools.ietf.org/html/rfc3986#section-3.3[RFC 3986] discusses name-value pairs in
|
||||
{rfc-site}/rfc3986#section-3.3[RFC 3986] discusses name-value pairs in
|
||||
path segments. In Spring MVC, we refer to those as "`matrix variables`" based on an
|
||||
https://www.w3.org/DesignIssues/MatrixURIs.html["`old post`"] by Tim Berners-Lee, but they
|
||||
can be also be referred to as URI path parameters.
|
||||
|
||||
@@ -242,5 +242,5 @@ xref:web/webmvc/mvc-controller/ann-validation.adoc[Validation].
|
||||
|
||||
TIP: Using `@ModelAttribute` is optional. By default, any parameter that is not a simple
|
||||
value type as determined by
|
||||
{api-spring-framework}/beans/BeanUtils.html#isSimpleProperty-java.lang.Class-[BeanUtils#isSimpleProperty]
|
||||
{spring-framework-api}/beans/BeanUtils.html#isSimpleProperty-java.lang.Class-[BeanUtils#isSimpleProperty]
|
||||
_AND_ that is not resolved by any other argument resolver is treated as an `@ModelAttribute`.
|
||||
|
||||
@@ -75,7 +75,7 @@ then the map is populated with the request parameter values for each given param
|
||||
|
||||
Note that use of `@RequestParam` is optional (for example, to set its attributes).
|
||||
By default, any argument that is a simple value type (as determined by
|
||||
{api-spring-framework}/beans/BeanUtils.html#isSimpleProperty-java.lang.Class-[BeanUtils#isSimpleProperty])
|
||||
{spring-framework-api}/beans/BeanUtils.html#isSimpleProperty-java.lang.Class-[BeanUtils#isSimpleProperty])
|
||||
and is not resolved by any other argument resolver, is treated as if it were annotated
|
||||
with `@RequestParam`.
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ supported for all return values.
|
||||
| Other return values
|
||||
| If a return value remains unresolved in any other way, it is treated as a model
|
||||
attribute, unless it is a simple type as determined by
|
||||
{api-spring-framework}/beans/BeanUtils.html#isSimpleProperty-java.lang.Class-[BeanUtils#isSimpleProperty],
|
||||
{spring-framework-api}/beans/BeanUtils.html#isSimpleProperty-java.lang.Class-[BeanUtils#isSimpleProperty],
|
||||
in which case it remains unresolved.
|
||||
|===
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ Kotlin::
|
||||
|
||||
|
||||
NOTE: When a name is not explicitly specified, a default name is chosen based on the `Object`
|
||||
type, as explained in the javadoc for {api-spring-framework}/core/Conventions.html[`Conventions`].
|
||||
type, as explained in the javadoc for {spring-framework-api}/core/Conventions.html[`Conventions`].
|
||||
You can always assign an explicit name by using the overloaded `addAttribute` method or
|
||||
through the `name` attribute on `@ModelAttribute` (for a return value).
|
||||
|
||||
|
||||
@@ -104,8 +104,8 @@ at the end of a path. `PathPattern` also restricts the use of `+**+` for matchin
|
||||
path segments such that it's only allowed at the end of a pattern. This eliminates many
|
||||
cases of ambiguity when choosing the best matching pattern for a given request.
|
||||
For full pattern syntax please refer to
|
||||
{api-spring-framework}/web/util/pattern/PathPattern.html[PathPattern] and
|
||||
{api-spring-framework}/util/AntPathMatcher.html[AntPathMatcher].
|
||||
{spring-framework-api}/web/util/pattern/PathPattern.html[PathPattern] and
|
||||
{spring-framework-api}/util/AntPathMatcher.html[AntPathMatcher].
|
||||
|
||||
Some example patterns:
|
||||
|
||||
@@ -226,8 +226,8 @@ some external configuration.
|
||||
When multiple patterns match a URL, the best match must be selected. This is done with
|
||||
one of the following depending on whether use of parsed `PathPattern` is enabled for use or not:
|
||||
|
||||
* {api-spring-framework}/web/util/pattern/PathPattern.html#SPECIFICITY_COMPARATOR[`PathPattern.SPECIFICITY_COMPARATOR`]
|
||||
* {api-spring-framework}/util/AntPathMatcher.html#getPatternComparator-java.lang.String-[`AntPathMatcher.getPatternComparator(String path)`]
|
||||
* {spring-framework-api}/web/util/pattern/PathPattern.html#SPECIFICITY_COMPARATOR[`PathPattern.SPECIFICITY_COMPARATOR`]
|
||||
* {spring-framework-api}/util/AntPathMatcher.html#getPatternComparator-java.lang.String-[`AntPathMatcher.getPatternComparator(String path)`]
|
||||
|
||||
Both help to sort patterns with more specific ones on top. A pattern is more specific if
|
||||
it has a lower count of URI variables (counted as 1), single wildcards (counted as 1),
|
||||
@@ -296,7 +296,7 @@ Many common path extensions are allowed as safe by default. Applications with cu
|
||||
negotiation to avoid having a `Content-Disposition` header added for those extensions.
|
||||
See xref:web/webmvc/mvc-config/content-negotiation.adoc[Content Types].
|
||||
|
||||
See https://pivotal.io/security/cve-2015-5211[CVE-2015-5211] for additional
|
||||
See {spring-site-cve}/cve-2015-5211[CVE-2015-5211] for additional
|
||||
recommendations related to RFD.
|
||||
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ raise `MethodArgumentNotValidException` in case of validation errors. If you wan
|
||||
the errors in the controller method instead, you can declare an `Errors` or `BindingResult`
|
||||
method parameter immediately after the validated parameter.
|
||||
|
||||
Second, if https://beanvalidation.org/[Java Bean Validation] is present _AND_ other method
|
||||
Second, if {bean-validation-site}[Java Bean Validation] is present _AND_ other method
|
||||
parameters, e.g. `@RequestHeader`, `@RequestParam`, `@PathVariable` have `@Constraint`
|
||||
annotations, then method validation is applied to all method arguments, raising
|
||||
`HandlerMethodValidationException` in case of validation errors. You can still declare an
|
||||
|
||||
@@ -8,7 +8,7 @@ Servlet 4 containers are required to support HTTP/2, and Spring Framework 5 is c
|
||||
with Servlet API 4. From a programming model perspective, there is nothing specific that
|
||||
applications need to do. However, there are considerations related to server configuration.
|
||||
For more details, see the
|
||||
https://github.com/spring-projects/spring-framework/wiki/HTTP-2-support[HTTP/2 wiki page].
|
||||
{spring-framework-wiki}/HTTP-2-support[HTTP/2 wiki page].
|
||||
|
||||
The Servlet API does expose one construct related to HTTP/2. You can use the
|
||||
`jakarta.servlet.http.PushBuilder` to proactively push resources to clients, and it
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
[.small]#xref:web/webflux/security.adoc[See equivalent in the Reactive stack]#
|
||||
|
||||
The https://spring.io/projects/spring-security[Spring Security] project provides support
|
||||
The {spring-site-projects}/spring-security[Spring Security] project provides support
|
||||
for protecting web applications from malicious exploits. See the Spring Security
|
||||
reference documentation, including:
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ NOTE: In addition to using the ServletContext API directly, you can also extend
|
||||
|
||||
NOTE: For programmatic use cases, a `GenericWebApplicationContext` can be used as an
|
||||
alternative to `AnnotationConfigWebApplicationContext`. See the
|
||||
{api-spring-framework}/web/context/support/GenericWebApplicationContext.html[`GenericWebApplicationContext`]
|
||||
{spring-framework-api}/web/context/support/GenericWebApplicationContext.html[`GenericWebApplicationContext`]
|
||||
javadoc for details.
|
||||
|
||||
The following example of `web.xml` configuration registers and initializes the `DispatcherServlet`:
|
||||
@@ -111,7 +111,7 @@ the lifecycle of the Servlet container, Spring Boot uses Spring configuration to
|
||||
bootstrap itself and the embedded Servlet container. `Filter` and `Servlet` declarations
|
||||
are detected in Spring configuration and registered with the Servlet container.
|
||||
For more details, see the
|
||||
https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-embedded-container[Spring Boot documentation].
|
||||
{spring-boot-docs}/web.html#web.servlet.embedded-container[Spring Boot documentation].
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ Applications can declare the infrastructure beans listed in xref:web/webmvc/mvc-
|
||||
that are required to process requests. The `DispatcherServlet` checks the
|
||||
`WebApplicationContext` for each special bean. If there are no matching bean types,
|
||||
it falls back on the default types listed in
|
||||
{spring-framework-main-code}/spring-webmvc/src/main/resources/org/springframework/web/servlet/DispatcherServlet.properties[`DispatcherServlet.properties`].
|
||||
{spring-framework-code}/spring-webmvc/src/main/resources/org/springframework/web/servlet/DispatcherServlet.properties[`DispatcherServlet.properties`].
|
||||
|
||||
In most cases, the xref:web/webmvc/mvc-config.adoc[MVC Config] is the best starting point. It declares the required
|
||||
beans in either Java or XML and provides a higher-level configuration callback API to
|
||||
|
||||
@@ -19,7 +19,7 @@ The following table lists the available `HandlerExceptionResolver` implementatio
|
||||
| A mapping between exception class names and error view names. Useful for rendering
|
||||
error pages in a browser application.
|
||||
|
||||
| {api-spring-framework}/web/servlet/mvc/support/DefaultHandlerExceptionResolver.html[`DefaultHandlerExceptionResolver`]
|
||||
| {spring-framework-api}/web/servlet/mvc/support/DefaultHandlerExceptionResolver.html[`DefaultHandlerExceptionResolver`]
|
||||
| Resolves exceptions raised by Spring MVC and maps them to HTTP status codes.
|
||||
See also alternative `ResponseEntityExceptionHandler` and xref:web/webmvc/mvc-ann-rest-exceptions.adoc[Error Responses].
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ This resolver variant uses your Servlet container's multipart parser as-is,
|
||||
potentially exposing the application to container implementation differences.
|
||||
By default, it will try to parse any `multipart/` content type with any HTTP
|
||||
method but this may not be supported across all Servlet containers. See the
|
||||
{api-spring-framework}/web/multipart/support/StandardServletMultipartResolver.html[`StandardServletMultipartResolver`]
|
||||
{spring-framework-api}/web/multipart/support/StandardServletMultipartResolver.html[`StandardServletMultipartResolver`]
|
||||
javadoc for details and configuration options.
|
||||
====
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ The following table provides more details on the `ViewResolver` hierarchy:
|
||||
| Convenient subclass of `UrlBasedViewResolver` that supports `InternalResourceView` (in
|
||||
effect, Servlets and JSPs) and subclasses such as `JstlView`. You can specify the view
|
||||
class for all views generated by this resolver by using `setViewClass(..)`.
|
||||
See the {api-spring-framework}/web/reactive/result/view/UrlBasedViewResolver.html[`UrlBasedViewResolver`]
|
||||
See the {spring-framework-api}/web/reactive/result/view/UrlBasedViewResolver.html[`UrlBasedViewResolver`]
|
||||
javadoc for details.
|
||||
|
||||
| `FreeMarkerViewResolver`
|
||||
@@ -103,7 +103,7 @@ Servlet/JSP engine. Note that you may also chain multiple view resolvers, instea
|
||||
== Content Negotiation
|
||||
[.small]#xref:web/webflux/dispatcher-handler.adoc#webflux-multiple-representations[See equivalent in the Reactive stack]#
|
||||
|
||||
{api-spring-framework}/web/servlet/view/ContentNegotiatingViewResolver.html[`ContentNegotiatingViewResolver`]
|
||||
{spring-framework-api}/web/servlet/view/ContentNegotiatingViewResolver.html[`ContentNegotiatingViewResolver`]
|
||||
does not resolve views itself but rather delegates
|
||||
to other view resolvers and selects the view that resembles the representation requested
|
||||
by the client. The representation can be determined from the `Accept` header or from a
|
||||
|
||||
@@ -23,20 +23,20 @@ change application code.
|
||||
|
||||
SockJS consists of:
|
||||
|
||||
* The https://github.com/sockjs/sockjs-protocol[SockJS protocol]
|
||||
* The {sockjs-protocol}[SockJS protocol]
|
||||
defined in the form of executable
|
||||
https://sockjs.github.io/sockjs-protocol/sockjs-protocol-0.3.3.html[narrated tests].
|
||||
* The https://github.com/sockjs/sockjs-client/[SockJS JavaScript client] -- a client library for use in browsers.
|
||||
{sockjs-protocol-site}/sockjs-protocol-0.3.3.html[narrated tests].
|
||||
* The {sockjs-client}[SockJS JavaScript client] -- a client library for use in browsers.
|
||||
* SockJS server implementations, including one in the Spring Framework `spring-websocket` module.
|
||||
* A SockJS Java client in the `spring-websocket` module (since version 4.1).
|
||||
|
||||
SockJS is designed for use in browsers. It uses a variety of techniques
|
||||
to support a wide range of browser versions.
|
||||
For the full list of SockJS transport types and browsers, see the
|
||||
https://github.com/sockjs/sockjs-client/[SockJS client] page. Transports
|
||||
{sockjs-client}[SockJS client] page. Transports
|
||||
fall in three general categories: WebSocket, HTTP Streaming, and HTTP Long Polling.
|
||||
For an overview of these categories, see
|
||||
https://spring.io/blog/2012/05/08/spring-mvc-3-2-preview-techniques-for-real-time-updates/[this blog post].
|
||||
{spring-site-blog}/2012/05/08/spring-mvc-3-2-preview-techniques-for-real-time-updates/[this blog post].
|
||||
|
||||
The SockJS client begins by sending `GET /info` to
|
||||
obtain basic information from the server. After that, it must decide what transport
|
||||
@@ -130,13 +130,13 @@ The preceding example is for use in Spring MVC applications and should be includ
|
||||
configuration of a xref:web/webmvc/mvc-servlet.adoc[`DispatcherServlet`]. However, Spring's WebSocket
|
||||
and SockJS support does not depend on Spring MVC. It is relatively simple to
|
||||
integrate into other HTTP serving environments with the help of
|
||||
{api-spring-framework}/web/socket/sockjs/support/SockJsHttpRequestHandler.html[`SockJsHttpRequestHandler`].
|
||||
{spring-framework-api}/web/socket/sockjs/support/SockJsHttpRequestHandler.html[`SockJsHttpRequestHandler`].
|
||||
|
||||
On the browser side, applications can use the
|
||||
https://github.com/sockjs/sockjs-client/[`sockjs-client`] (version 1.0.x). It
|
||||
{sockjs-client}[`sockjs-client`] (version 1.0.x). It
|
||||
emulates the W3C WebSocket API and communicates with the server to select the best
|
||||
transport option, depending on the browser in which it runs. See the
|
||||
https://github.com/sockjs/sockjs-client/[sockjs-client] page and the list of
|
||||
{sockjs-client}[sockjs-client] page and the list of
|
||||
transport types supported by browser. The client also provides several
|
||||
configuration options -- for example, to specify which transports to include.
|
||||
|
||||
@@ -183,7 +183,7 @@ but can be configured to do so. In the future, it may set it by default.
|
||||
See {docs-spring-security}/features/exploits/headers.html#headers-default[Default Security Headers]
|
||||
of the Spring Security documentation for details on how to configure the
|
||||
setting of the `X-Frame-Options` header. You can also see
|
||||
https://github.com/spring-projects/spring-security/issues/2718[gh-2718]
|
||||
{spring-github-org}/spring-security/issues/2718[gh-2718]
|
||||
for additional background.
|
||||
====
|
||||
|
||||
@@ -219,7 +219,7 @@ The XML namespace provides a similar option through the `<websocket:sockjs>` ele
|
||||
NOTE: During initial development, do enable the SockJS client `devel` mode that prevents
|
||||
the browser from caching SockJS requests (like the iframe) that would otherwise
|
||||
be cached. For details on how to enable it see the
|
||||
https://github.com/sockjs/sockjs-client/[SockJS client] page.
|
||||
{sockjs-client}[SockJS client] page.
|
||||
|
||||
|
||||
|
||||
@@ -231,7 +231,7 @@ from concluding that a connection is hung. The Spring SockJS configuration has a
|
||||
called `heartbeatTime` that you can use to customize the frequency. By default, a
|
||||
heartbeat is sent after 25 seconds, assuming no other messages were sent on that
|
||||
connection. This 25-second value is in line with the following
|
||||
https://tools.ietf.org/html/rfc6202[IETF recommendation] for public Internet applications.
|
||||
{rfc-site}/rfc6202[IETF recommendation] for public Internet applications.
|
||||
|
||||
NOTE: When using STOMP over WebSocket and SockJS, if the STOMP client and server negotiate
|
||||
heartbeats to be exchanged, the SockJS heartbeats are disabled.
|
||||
@@ -248,7 +248,7 @@ should consider customizing the settings according to your specific needs.
|
||||
|
||||
HTTP streaming and HTTP long polling SockJS transports require a connection to remain
|
||||
open longer than usual. For an overview of these techniques, see
|
||||
https://spring.io/blog/2012/05/08/spring-mvc-3-2-preview-techniques-for-real-time-updates/[this blog post].
|
||||
{spring-site-blog}/2012/05/08/spring-mvc-3-2-preview-techniques-for-real-time-updates/[this blog post].
|
||||
|
||||
In Servlet containers, this is done through Servlet 3 asynchronous support that
|
||||
allows exiting the Servlet container thread, processing a request, and continuing
|
||||
|
||||
@@ -84,13 +84,13 @@ The preceding example is for use in Spring MVC applications and should be includ
|
||||
in the configuration of a xref:web/webmvc/mvc-servlet.adoc[`DispatcherServlet`]. However, Spring's
|
||||
WebSocket support does not depend on Spring MVC. It is relatively simple to
|
||||
integrate a `WebSocketHandler` into other HTTP-serving environments with the help of
|
||||
{api-spring-framework}/web/socket/server/support/WebSocketHttpRequestHandler.html[`WebSocketHttpRequestHandler`].
|
||||
{spring-framework-api}/web/socket/server/support/WebSocketHttpRequestHandler.html[`WebSocketHttpRequestHandler`].
|
||||
|
||||
When using the `WebSocketHandler` API directly vs indirectly, e.g. through the
|
||||
xref:web/websocket/stomp.adoc[STOMP] messaging, the application must synchronize the sending of messages
|
||||
since the underlying standard WebSocket session (JSR-356) does not allow concurrent
|
||||
sending. One option is to wrap the `WebSocketSession` with
|
||||
{api-spring-framework}/web/socket/handler/ConcurrentWebSocketSessionDecorator.html[`ConcurrentWebSocketSessionDecorator`].
|
||||
{spring-framework-api}/web/socket/handler/ConcurrentWebSocketSessionDecorator.html[`ConcurrentWebSocketSessionDecorator`].
|
||||
|
||||
|
||||
|
||||
@@ -315,7 +315,7 @@ As of Spring Framework 4.1.5, the default behavior for WebSocket and SockJS is t
|
||||
only same-origin requests. It is also possible to allow all or a specified list of origins.
|
||||
This check is mostly designed for browser clients. Nothing prevents other types
|
||||
of clients from modifying the `Origin` header value (see
|
||||
https://tools.ietf.org/html/rfc6454[RFC 6454: The Web Origin Concept] for more details).
|
||||
{rfc-site}/rfc6454[RFC 6454: The Web Origin Concept] for more details).
|
||||
|
||||
The three possible behaviors are:
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[[websocket-stomp-authentication-token-based]]
|
||||
= Token Authentication
|
||||
|
||||
https://github.com/spring-projects/spring-security-oauth[Spring Security OAuth]
|
||||
{spring-github-org}/spring-security-oauth[Spring Security OAuth]
|
||||
provides support for token based security, including JSON Web Token (JWT).
|
||||
You can use this as the authentication mechanism in Web applications,
|
||||
including STOMP over WebSocket interactions, as described in the previous
|
||||
@@ -11,13 +11,13 @@ At the same time, cookie-based sessions are not always the best fit (for example
|
||||
in applications that do not maintain a server-side session or in
|
||||
mobile applications where it is common to use headers for authentication).
|
||||
|
||||
The https://tools.ietf.org/html/rfc6455#section-10.5[WebSocket protocol, RFC 6455]
|
||||
The {rfc-site}/rfc6455#section-10.5[WebSocket protocol, RFC 6455]
|
||||
"doesn't prescribe any particular way that servers can authenticate clients during
|
||||
the WebSocket handshake." In practice, however, browser clients can use only standard
|
||||
authentication headers (that is, basic HTTP authentication) or cookies and cannot (for example)
|
||||
provide custom headers. Likewise, the SockJS JavaScript client does not provide
|
||||
a way to send HTTP headers with SockJS transport requests. See
|
||||
https://github.com/sockjs/sockjs-client/issues/196[sockjs-client issue 196].
|
||||
{sockjs-client}/issues/196[sockjs-client issue 196].
|
||||
Instead, it does allow sending query parameters that you can use to send a token,
|
||||
but that has its own drawbacks (for example, the token may be inadvertently
|
||||
logged with the URL in server logs).
|
||||
|
||||
@@ -6,7 +6,7 @@ Spring Security provides
|
||||
{docs-spring-security}/servlet/integrations/websocket.html#websocket-authorization[WebSocket sub-protocol authorization]
|
||||
that uses a `ChannelInterceptor` to authorize messages based on the user header in them.
|
||||
Also, Spring Session provides
|
||||
https://docs.spring.io/spring-session/reference/web-socket.html[WebSocket integration]
|
||||
{docs-spring-session}/web-socket.html[WebSocket integration]
|
||||
that ensures the user's HTTP session does not expire while the WebSocket session is still active.
|
||||
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ and xref:web/websocket/stomp/authentication.adoc[Authentication] for more inform
|
||||
|
||||
For more example code see:
|
||||
|
||||
* https://spring.io/guides/gs/messaging-stomp-websocket/[Using WebSocket to build an
|
||||
* {spring-site-guides}/gs/messaging-stomp-websocket/[Using WebSocket to build an
|
||||
interactive web application] -- a getting started guide.
|
||||
* https://github.com/rstoyanchev/spring-websocket-portfolio[Stock Portfolio] -- a sample
|
||||
application.
|
||||
|
||||
@@ -59,7 +59,7 @@ The following example shows the XML configuration equivalent of the preceding ex
|
||||
----
|
||||
|
||||
The STOMP broker relay in the preceding configuration is a Spring
|
||||
{api-spring-framework}/messaging/MessageHandler.html[`MessageHandler`]
|
||||
{spring-framework-api}/messaging/MessageHandler.html[`MessageHandler`]
|
||||
that handles messages by forwarding them to an external message broker.
|
||||
To do so, it establishes TCP connections to the broker, forwards all messages to it,
|
||||
and then forwards all messages received from the broker to clients through their
|
||||
|
||||
@@ -7,18 +7,18 @@ connected clients. This section describes the flow of messages on the server sid
|
||||
The `spring-messaging` module contains foundational support for messaging applications
|
||||
that originated in https://spring.io/spring-integration[Spring Integration] and was
|
||||
later extracted and incorporated into the Spring Framework for broader use across many
|
||||
https://spring.io/projects[Spring projects] and application scenarios.
|
||||
{spring-site-projects}[Spring projects] and application scenarios.
|
||||
The following list briefly describes a few of the available messaging abstractions:
|
||||
|
||||
* {api-spring-framework}/messaging/Message.html[Message]:
|
||||
* {spring-framework-api}/messaging/Message.html[Message]:
|
||||
Simple representation for a message, including headers and payload.
|
||||
* {api-spring-framework}/messaging/MessageHandler.html[MessageHandler]:
|
||||
* {spring-framework-api}/messaging/MessageHandler.html[MessageHandler]:
|
||||
Contract for handling a message.
|
||||
* {api-spring-framework}/messaging/MessageChannel.html[MessageChannel]:
|
||||
* {spring-framework-api}/messaging/MessageChannel.html[MessageChannel]:
|
||||
Contract for sending a message that enables loose coupling between producers and consumers.
|
||||
* {api-spring-framework}/messaging/SubscribableChannel.html[SubscribableChannel]:
|
||||
* {spring-framework-api}/messaging/SubscribableChannel.html[SubscribableChannel]:
|
||||
`MessageChannel` with `MessageHandler` subscribers.
|
||||
* {api-spring-framework}/messaging/support/ExecutorSubscribableChannel.html[ExecutorSubscribableChannel]:
|
||||
* {spring-framework-api}/messaging/support/ExecutorSubscribableChannel.html[ExecutorSubscribableChannel]:
|
||||
`SubscribableChannel` that uses an `Executor` for delivering messages.
|
||||
|
||||
Both the Java configuration (that is, `@EnableWebSocketMessageBroker`) and the XML namespace configuration
|
||||
|
||||
Reference in New Issue
Block a user