Update links between WebFlux and Web MVC

This commit is contained in:
Rossen Stoyanchev 2019-11-26 21:50:01 +00:00
parent 30d68f2de7
commit 5a552f1670
10 changed files with 195 additions and 195 deletions

View File

@ -1113,7 +1113,7 @@ converters to use explicitly.
[[rest-message-conversion]]
===== Message Conversion
[.small]#<<web-reactive.adoc#webflux-codecs, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-codecs, WebFlux>>#
The `spring-web` module contains the `HttpMessageConverter` contract for reading and
writing the body of HTTP requests and responses through `InputStream` and `OutputStream`.

View File

@ -1,6 +1,6 @@
[[webflux-cors]]
= CORS
[.small]#<<web.adoc#mvc-cors, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-cors, Web MVC>>#
Spring WebFlux lets you handle CORS (Cross-Origin Resource Sharing). This section
describes how to do so.
@ -10,7 +10,7 @@ describes how to do so.
[[webflux-cors-intro]]
== Introduction
[.small]#<<web.adoc#mvc-cors-intro, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-cors-intro, Web MVC>>#
For security reasons, browsers prohibit AJAX calls to resources outside the current origin.
For example, you could have your bank account in one tab and evil.com in another. Scripts
@ -27,7 +27,7 @@ powerful workarounds based on IFRAME or JSONP.
[[webflux-cors-processing]]
== Processing
[.small]#<<web.adoc#mvc-cors-processing, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-cors-processing, Web MVC>>#
The CORS specification distinguishes between preflight, simple, and actual requests.
To learn how CORS works, you can read
@ -77,7 +77,7 @@ To learn more from the source or to make advanced customizations, see:
[[webflux-cors-controller]]
== `@CrossOrigin`
[.small]#<<web.adoc#mvc-cors-controller, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-cors-controller, Web MVC>>#
The {api-spring-framework}/web/bind/annotation/CrossOrigin.html[`@CrossOrigin`]
annotation enables cross-origin requests on annotated controller methods, as the
@ -230,7 +230,7 @@ as the following example shows:
[[webflux-cors-global]]
== Global Configuration
[.small]#<<web.adoc#mvc-cors-global, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-cors-global, Web MVC>>#
In addition to fine-grained, controller method-level configuration, you probably want to
define some global CORS configuration, too. You can set URL-based `CorsConfiguration`
@ -299,7 +299,7 @@ as the following example shows:
[[webflux-cors-webfilter]]
== CORS `WebFilter`
[.small]#<<web.adoc#mvc-cors-filter, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-cors-filter, Web MVC>>#
You can apply CORS support through the built-in
{api-spring-framework}/web/cors/reactive/CorsWebFilter.html[`CorsWebFilter`], which is a

View File

@ -1,6 +1,6 @@
[[webflux-fn]]
= Functional Endpoints
[.small]#<<web.adoc#webmvc-fn, Same as in Spring MVC>>#
[.small]#<<web.adoc#webmvc-fn, Web MVC>>#
Spring WebFlux includes WebFlux.fn, a lightweight functional programming model in which functions
are used to route and handle requests and contracts are designed for immutability.
@ -12,7 +12,7 @@ the same <<web-reactive.adoc#webflux-reactive-spring-web>> foundation.
[[webflux-fn-overview]]
== Overview
[.small]#<<web.adoc#webmvc-fn-overview, Same as in Spring MVC>>#
[.small]#<<web.adoc#webmvc-fn-overview, Web MVC>>#
In WebFlux.fn, an HTTP request is handled with a `HandlerFunction`: a function that takes
`ServerRequest` and returns a delayed `ServerResponse` (i.e. `Mono<ServerResponse>`).
@ -112,7 +112,7 @@ Most applications can run through the WebFlux Java configuration, see <<webflux-
[[webflux-fn-handler-functions]]
== HandlerFunction
[.small]#<<web.adoc#webmvc-fn-handler-functions, Same as in Spring MVC>>#
[.small]#<<web.adoc#webmvc-fn-handler-functions, Web MVC>>#
`ServerRequest` and `ServerResponse` are immutable interfaces that offer JDK 8-friendly
access to the HTTP request and response.
@ -440,7 +440,7 @@ See <<core.adoc#validation-beanvalidation, Spring Validation>>.
[[webflux-fn-router-functions]]
== `RouterFunction`
[.small]#<<web.adoc#webmvc-fn-router-functions, Same as in Spring MVC>>#
[.small]#<<web.adoc#webmvc-fn-router-functions, Web MVC>>#
Router functions are used to route the requests to the corresponding `HandlerFunction`.
Typically, you do not write router functions yourself, but rather use a method on the
@ -639,7 +639,7 @@ We can further improve by using the `nest` method together with `accept`:
[[webflux-fn-running]]
== Running a Server
[.small]#<<web.adoc#webmvc-fn-running, Same as in Spring MVC>>#
[.small]#<<web.adoc#webmvc-fn-running, Web MVC>>#
How do you run a router function in an HTTP server? A simple option is to convert a router
function to an `HttpHandler` by using one of the following:
@ -745,7 +745,7 @@ The following example shows a WebFlux Java configuration (see
[[webflux-fn-handler-filter-function]]
== Filtering Handler Functions
[.small]#<<web.adoc#webmvc-fn-handler-filter-function, Same as in Spring MVC>>#
[.small]#<<web.adoc#webmvc-fn-handler-filter-function, Web MVC>>#
You can filter handler functions by using the `before`, `after`, or `filter` methods on the routing
function builder.

View File

@ -1,6 +1,6 @@
[[webflux-view]]
= View Technologies
[.small]#<<web.adoc#mvc-view, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-view, Web MVC>>#
The use of view technologies in Spring WebFlux is pluggable. Whether you decide to
use Thymeleaf, FreeMarker, or some other view technology is primarily a matter of a
@ -12,7 +12,7 @@ WebFlux. We assume you are already familiar with <<webflux-viewresolution>>.
[[webflux-view-thymeleaf]]
== Thymeleaf
[.small]#<<web.adoc#mvc-view-thymeleaf, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-view-thymeleaf, Web MVC>>#
Thymeleaf is a modern server-side Java template engine that emphasizes natural HTML
templates that can be previewed in a browser by double-clicking, which is very
@ -33,7 +33,7 @@ http://forum.thymeleaf.org/Thymeleaf-3-0-8-JUST-PUBLISHED-td4030687.html[announc
[[webflux-view-freemarker]]
== FreeMarker
[.small]#<<web.adoc#mvc-view-freemarker, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-view-freemarker, Web MVC>>#
https://freemarker.apache.org/[Apache FreeMarker] is a template engine for generating any
kind of text output from HTML to email and others. The Spring Framework has built-in
@ -43,7 +43,7 @@ integration for using Spring WebFlux with FreeMarker templates.
[[webflux-view-freemarker-contextconfig]]
=== View Configuration
[.small]#<<web.adoc#mvc-view-freemarker-contextconfig, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-view-freemarker-contextconfig, Web MVC>>#
The following example shows how to configure FreeMarker as a view technology:
@ -98,7 +98,7 @@ returns the view name, `welcome`, the resolver looks for the
[[webflux-views-freemarker]]
=== FreeMarker Configuration
[.small]#<<web.adoc#mvc-views-freemarker, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-views-freemarker, Web MVC>>#
You can pass FreeMarker 'Settings' and 'SharedVariables' directly to the FreeMarker
`Configuration` object (which is managed by Spring) by setting the appropriate bean
@ -151,7 +151,7 @@ the `Configuration` object.
[[webflux-view-freemarker-forms]]
=== Form Handling
[.small]#<<web.adoc#mvc-view-freemarker-forms, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-view-freemarker-forms, Web MVC>>#
Spring provides a tag library for use in JSPs that contains, among others, a
`<spring:bind/>` element. This element primarily lets forms display values from
@ -162,7 +162,7 @@ with additional convenience macros for generating form input elements themselves
[[webflux-view-bind-macros]]
==== The Bind Macros
[.small]#<<web.adoc#mvc-view-bind-macros, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-view-bind-macros, Web MVC>>#
A standard set of macros are maintained within the `spring-webflux.jar` file for
FreeMarker, so they are always available to a suitably configured application.
@ -193,7 +193,7 @@ sections of the Spring MVC documentation.
[[webflux-view-script]]
== Script Views
[.small]#<<web.adoc#mvc-view-script, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-view-script, Web MVC>>#
The Spring Framework has a built-in integration for using Spring WebFlux with any
templating library that can run on top of the
@ -219,7 +219,7 @@ TIP: The basic rule for integrating any other script engine is that it must impl
[[webflux-view-script-dependencies]]
=== Requirements
[.small]#<<web.adoc#mvc-view-script-dependencies, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-view-script-dependencies, Web MVC>>#
You need to have the script engine on your classpath, the details of which vary by script engine:
@ -239,7 +239,7 @@ through https://www.webjars.org/[WebJars].
[[webflux-view-script-integrate]]
=== Script Templates
[.small]#<<web.adoc#mvc-view-script-integrate, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-view-script-integrate, Web MVC>>#
You can declare a `ScriptTemplateConfigurer` bean to specify the script engine to use,
the script files to load, what function to call to render templates, and so on.
@ -389,7 +389,7 @@ for more configuration examples.
[[webflux-view-httpmessagewriter]]
== JSON and XML
[.small]#<<web.adoc#mvc-view-jackson, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-view-jackson, Web MVC>>#
For <<webflux-multiple-representations>> purposes, it is useful to be able to alternate
between rendering a model with an HTML template or as other formats (such as JSON or XML),

View File

@ -594,7 +594,7 @@ The `DefaultServerWebExchange` uses the configured `HttpMessageReader` to parse
[[webflux-multipart]]
==== Multipart Data
[.small]#<<web.adoc#mvc-multipart, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-multipart, Web MVC>>#
`ServerWebExchange` exposes the following method for access to multipart data:
@ -626,7 +626,7 @@ content to `Flux<Part>` without collecting to a `MultiValueMap`.
[[webflux-forwarded-headers]]
==== Forwarded Headers
[.small]#<<web.adoc#filters-forwarded-headers, Same as in Spring MVC>>#
[.small]#<<web.adoc#filters-forwarded-headers, Web MVC>>#
As a request goes through proxies (such as load balancers), the host, port, and
scheme may change, and that makes it a challenge, from a client perspective, to create links that point to the correct
@ -657,7 +657,7 @@ filters, and `ForwardedHeaderTransformer` is used instead.
[[webflux-filters]]
=== Filters
[.small]#<<web.adoc#filters, Same as in Spring MVC>>#
[.small]#<<web.adoc#filters, Web MVC>>#
In the <<webflux-web-handler-api>>, you can use a `WebFilter` to apply interception-style
logic before and after the rest of the processing chain of filters and the target
@ -668,7 +668,7 @@ the bean declaration or by implementing `Ordered`.
[[webflux-filters-cors]]
==== CORS
[.small]#<<web.adoc#filters-cors, Same as in Spring MVC>>#
[.small]#<<web.adoc#filters-cors, Web MVC>>#
Spring WebFlux provides fine-grained support for CORS configuration through annotations on
controllers. However, when you use it with Spring Security, we advise relying on the built-in
@ -680,7 +680,7 @@ See the section on <<webflux-cors>> and the <<webflux-cors-webfilter>> for more
[[webflux-exception-handler]]
=== Exceptions
[.small]#<<web.adoc#mvc-ann-customer-servlet-container-error-page, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-ann-customer-servlet-container-error-page, Web MVC>>#
In the <<webflux-web-handler-api>>, you can use a `WebExceptionHandler` to handle
exceptions from the chain of `WebFilter` instances and the target `WebHandler`. When using the
@ -711,7 +711,7 @@ The following table describes the available `WebExceptionHandler` implementation
[[webflux-codecs]]
=== Codecs
[.small]#<<integration.adoc#rest-message-conversion, Same as in Spring MVC>>#
[.small]#<<integration.adoc#rest-message-conversion, Web MVC>>#
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
@ -847,7 +847,7 @@ To configure all 3 in WebFlux, you'll need to supply a pre-configured instance o
[[webflux-codecs-streaming]]
==== Streaming
[.small]#<<web.adoc#mvc-ann-async-http-streaming, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-ann-async-http-streaming, Web MVC>>#
When streaming to the HTTP response (for example, `text/event-stream`,
`application/stream+json`), it is important to send data periodically, in order to
@ -875,7 +875,7 @@ especially the section on <<core#databuffers-using, Using DataBuffer>>.
[[webflux-logging]]
=== Logging
[.small]#<<web.adoc#mvc-logging, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-logging, Web MVC>>#
DEBUG level logging in Spring WebFlux is designed to be compact, minimal, and
human-friendly. It focuses on high value bits of information that are useful over and
@ -907,7 +907,7 @@ while a fully formatted prefix based on that ID is available from
[[webflux-logging-sensitive-data]]
==== Sensitive Data
[.small]#<<web.adoc#mvc-logging-sensitive-data, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-logging-sensitive-data, Web MVC>>#
`DEBUG` and `TRACE` logging can log sensitive information. This is why form parameters and
headers are masked by default and you must explicitly enable their logging in full.
@ -967,7 +967,7 @@ The following example shows how to do so for client-side requests:
[[webflux-dispatcher-handler]]
== `DispatcherHandler`
[.small]#<<web.adoc#mvc-servlet, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-servlet, Web MVC>>#
Spring WebFlux, similarly to Spring MVC, is designed around the front controller pattern,
where a central `WebHandler`, the `DispatcherHandler`, provides a shared algorithm for
@ -1010,7 +1010,7 @@ The resulting `HttpHandler` is ready for use with a <<webflux-httphandler, serve
[[webflux-special-bean-types]]
=== Special Bean Types
[.small]#<<web.adoc#mvc-servlet-special-bean-types, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-servlet-special-bean-types, Web MVC>>#
The `DispatcherHandler` delegates to special beans to process requests and render the
appropriate responses. By "`special beans,`" we mean Spring-managed `Object` instances that
@ -1052,7 +1052,7 @@ there are also some other beans detected at a lower level (see
[[webflux-framework-config]]
=== WebFlux Config
[.small]#<<web.adoc#mvc-servlet-config, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-servlet-config, Web MVC>>#
Applications can declare the infrastructure beans (listed under
<<webflux-web-handler-api-special-beans, Web Handler API>> and
@ -1067,7 +1067,7 @@ many extra convenient options.
[[webflux-dispatcher-handler-sequence]]
=== Processing
[.small]#<<web.adoc#mvc-servlet-sequence, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-servlet-sequence, Web MVC>>#
`DispatcherHandler` processes requests as follows:
@ -1118,7 +1118,7 @@ as a `HandlerResult`, along with some additional context, and passed to the firs
[[webflux-dispatcher-exceptions]]
=== Exceptions
[.small]#<<web.adoc#mvc-exceptionhandlers, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-exceptionhandlers, Web MVC>>#
The `HandlerResult` returned from a `HandlerAdapter` can expose a function for error
handling based on some handler-specific mechanism. This error function is called if:
@ -1141,7 +1141,7 @@ See also <<webflux-ann-controller-exceptions>> in the "`Annotated Controller`" s
[[webflux-viewresolution]]
=== View Resolution
[.small]#<<web.adoc#mvc-viewresolver, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-viewresolver, Web MVC>>#
View resolution enables rendering to a browser with an HTML template and a model without
tying you to a specific view technology. In Spring WebFlux, view resolution is
@ -1152,7 +1152,7 @@ instance. The `View` is then used to render the response.
[[webflux-viewresolution-handling]]
==== Handling
[.small]#<<web.adoc#mvc-handling, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-handling, Web MVC>>#
The `HandlerResult` passed into `ViewResolutionResultHandler` contains the return value
from the handler and the model that contains attributes added during request
@ -1188,7 +1188,7 @@ See <<webflux-view>> for more on the view technologies integrated with Spring We
[[webflux-redirecting-redirect-prefix]]
==== Redirecting
[.small]#<<web.adoc#mvc-redirecting-redirect-prefix, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-redirecting-redirect-prefix, Web MVC>>#
The special `redirect:` prefix in a view name lets you perform a redirect. The
`UrlBasedViewResolver` (and sub-classes) recognize this as an instruction that a
@ -1203,7 +1203,7 @@ operate in terms of logical view names. A view name such as
[[webflux-multiple-representations]]
==== Content Negotiation
[.small]#<<web.adoc#mvc-multiple-representations, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-multiple-representations, Web MVC>>#
`ViewResolutionResultHandler` supports content negotiation. It compares the request
media types with the media types supported by each selected `View`. The first `View`
@ -1220,7 +1220,7 @@ always selected and used if they match the requested media type.
[[webflux-controller]]
== Annotated Controllers
[.small]#<<web.adoc#mvc-controller, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-controller, Web MVC>>#
Spring WebFlux provides an annotation-based programming model, where `@Controller` and
`@RestController` components use annotations to express request mappings, request input,
@ -1258,7 +1258,7 @@ In the preceding example, the method returns a `String` to be written to the res
[[webflux-ann-controller]]
=== `@Controller`
[.small]#<<web.adoc#mvc-ann-controller, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-ann-controller, Web MVC>>#
You can define controller beans by using a standard Spring bean definition.
The `@Controller` stereotype allows for auto-detection and is aligned with Spring general support
@ -1302,7 +1302,7 @@ directly to the response body versus view resolution and rendering with an HTML
[[webflux-ann-requestmapping]]
=== Request Mapping
[.small]#<<web.adoc#mvc-ann-requestmapping, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-ann-requestmapping, Web MVC>>#
The `@RequestMapping` annotation is used to map requests to controllers methods. It has
various attributes to match by URL, HTTP method, request parameters, headers, and media
@ -1366,7 +1366,7 @@ The following example uses type and method level mappings:
[[webflux-ann-requestmapping-uri-templates]]
==== URI Patterns
[.small]#<<web.adoc#mvc-ann-requestmapping-uri-templates, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-ann-requestmapping-uri-templates, Web MVC>>#
You can map requests by using glob patterns and wildcards:
@ -1480,7 +1480,7 @@ explicit, and less vulnerable to URL path based exploits.
[[webflux-ann-requestmapping-pattern-comparison]]
==== Pattern Comparison
[.small]#<<web.adoc#mvc-ann-requestmapping-pattern-comparison, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-ann-requestmapping-pattern-comparison, Web MVC>>#
When multiple patterns match a URL, they must be compared to find the best match. This is done
with `PathPattern.SPECIFICITY_COMPARATOR`, which looks for patterns that are more specific.
@ -1495,7 +1495,7 @@ sorted last instead. If two patterns are both catch-all, the longer is chosen.
[[webflux-ann-requestmapping-consumes]]
==== Consumable Media Types
[.small]#<<web.adoc#mvc-ann-requestmapping-consumes, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-ann-requestmapping-consumes, Web MVC>>#
You can narrow the request mapping based on the `Content-Type` of the request,
as the following example shows:
@ -1530,7 +1530,7 @@ TIP: `MediaType` provides constants for commonly used media types -- for example
[[webflux-ann-requestmapping-produces]]
==== Producible Media Types
[.small]#<<web.adoc#mvc-ann-requestmapping-produces, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-ann-requestmapping-produces, Web MVC>>#
You can narrow the request mapping based on the `Accept` request header and the list of
content types that a controller method produces, as the following example shows:
@ -1567,7 +1567,7 @@ TIP: `MediaType` provides constants for commonly used media types -- e.g.
[[webflux-ann-requestmapping-params-and-headers]]
==== Parameters and Headers
[.small]#<<web.adoc#mvc-ann-requestmapping-params-and-headers, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-ann-requestmapping-params-and-headers, Web MVC>>#
You can narrow request mappings based on query parameter conditions. You can test for the
presence of a query parameter (`myParam`), for its absence (`!myParam`), or for a
@ -1619,7 +1619,7 @@ You can also use the same with request header conditions, as the follwing exampl
[[webflux-ann-requestmapping-head-options]]
==== HTTP HEAD, OPTIONS
[.small]#<<web.adoc#mvc-ann-requestmapping-head-options, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-ann-requestmapping-head-options, Web MVC>>#
`@GetMapping` and `@RequestMapping(method=HttpMethod.GET)` support HTTP HEAD
transparently for request mapping purposes. Controller methods need not change.
@ -1640,7 +1640,7 @@ is not necessary in the common case.
[[webflux-ann-requestmapping-composed]]
==== Custom Annotations
[.small]#<<web.adoc#mvc-ann-requestmapping-composed, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-ann-requestmapping-composed, Web MVC>>#
Spring WebFlux supports the use of <<core.adoc#beans-meta-annotations, composed annotations>>
for request mapping. Those are annotations that are themselves meta-annotated with
@ -1661,7 +1661,7 @@ you can check the custom attribute and return your own `RequestCondition`.
[[webflux-ann-requestmapping-registration]]
==== Explicit Registrations
[.small]#<<web.adoc#mvc-ann-requestmapping-registration, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-ann-requestmapping-registration, Web MVC>>#
You can programmatically register Handler methods, which can be used for dynamic
registrations or for advanced cases, such as different instances of the same handler
@ -1718,7 +1718,7 @@ under different URLs. The following example shows how to do so:
[[webflux-ann-methods]]
=== Handler Methods
[.small]#<<web.adoc#mvc-ann-methods, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-ann-methods, Web MVC>>#
`@RequestMapping` handler methods have a flexible signature and can choose from a range of
supported controller method arguments and return values.
@ -1726,7 +1726,7 @@ supported controller method arguments and return values.
[[webflux-ann-arguments]]
==== Method Arguments
[.small]#<<web.adoc#mvc-ann-arguments, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-ann-arguments, Web MVC>>#
The following table shows the supported controller method arguments.
@ -1847,7 +1847,7 @@ and others) and is equivalent to `required=false`.
[[webflux-ann-return-types]]
==== Return Values
[.small]#<<web.adoc#mvc-ann-return-types, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-ann-return-types, Web MVC>>#
The following table shows the supported controller method return values. Note that reactive
types from libraries such as Reactor, RxJava, <<webflux-reactive-libraries, or other>> are
@ -1921,7 +1921,7 @@ generally supported for all return values.
[[webflux-ann-typeconversion]]
==== Type Conversion
[.small]#<<web.adoc#mvc-ann-typeconversion, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-ann-typeconversion, Web MVC>>#
Some annotated controller method arguments that represent String-based request input (for example,
`@RequestParam`, `@RequestHeader`, `@PathVariable`, `@MatrixVariable`, and `@CookieValue`)
@ -1935,7 +1935,7 @@ can be customized through a `WebDataBinder` (see <<mvc-ann-initbinder>>) or by r
[[webflux-ann-matrix-variables]]
==== Matrix Variables
[.small]#<<web.adoc#mvc-ann-matrix-variables, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-ann-matrix-variables, Web MVC>>#
https://tools.ietf.org/html/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
@ -2070,7 +2070,7 @@ To get all matrix variables, use a `MultiValueMap`, as the following example sho
[[webflux-ann-requestparam]]
==== `@RequestParam`
[.small]#<<web.adoc#mvc-ann-requestparam, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-ann-requestparam, Web MVC>>#
You can use the `@RequestParam` annotation to bind query parameters to a method argument in a
controller. The following code snippet shows the usage:
@ -2145,7 +2145,7 @@ with `@RequestParam`.
[[webflux-ann-requestheader]]
==== `@RequestHeader`
[.small]#<<web.adoc#mvc-ann-requestheader, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-ann-requestheader, Web MVC>>#
You can use the `@RequestHeader` annotation to bind a request header to a method argument in a
controller.
@ -2206,7 +2206,7 @@ example, a method parameter annotated with `@RequestHeader("Accept")` may be of
[[webflux-ann-cookievalue]]
==== `@CookieValue`
[.small]#<<web.adoc#mvc-ann-cookievalue, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-ann-cookievalue, Web MVC>>#
You can use the `@CookieValue` annotation to bind the value of an HTTP cookie to a method argument
in a controller.
@ -2247,7 +2247,7 @@ Type conversion is applied automatically if the target method parameter type is
[[webflux-ann-modelattrib-method-args]]
==== `@ModelAttribute`
[.small]#<<web.adoc#mvc-ann-modelattrib-method-args, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-ann-modelattrib-method-args, Web MVC>>#
You can use the `@ModelAttribute` annotation on a method argument to access an attribute from the
model or have it instantiated if not present. The model attribute is also overlain with
@ -2394,7 +2394,7 @@ with `@ModelAttribute`.
[[webflux-ann-sessionattributes]]
==== `@SessionAttributes`
[.small]#<<web.adoc#mvc-ann-sessionattributes, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-ann-sessionattributes, Web MVC>>#
`@SessionAttributes` is used to store model attributes in the `WebSession` between
requests. It is a type-level annotation that declares session attributes used by a
@ -2479,7 +2479,7 @@ as the following example shows:
[[webflux-ann-sessionattribute]]
==== `@SessionAttribute`
[.small]#<<web.adoc#mvc-ann-sessionattribute, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-ann-sessionattribute, Web MVC>>#
If you need access to pre-existing session attributes that are managed globally
(that is, outside the controller -- for example, by a filter) and may or may not be present,
@ -2515,7 +2515,7 @@ workflow, consider using `SessionAttributes`, as described in
[[webflux-ann-requestattrib]]
==== `@RequestAttribute`
[.small]#<<web.adoc#mvc-ann-requestattrib, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-ann-requestattrib, Web MVC>>#
Similarly to `@SessionAttribute`, you can use the `@RequestAttribute` annotation to
access pre-existing request attributes created earlier (for example, by a `WebFilter`),
@ -2544,7 +2544,7 @@ as the following example shows:
[[webflux-multipart-forms]]
==== Multipart Content
[.small]#<<web.adoc#mvc-multipart-forms, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-multipart-forms, Web MVC>>#
As explained in <<webflux-multipart>>, `ServerWebExchange` provides access to multipart
content. The best way to handle a file upload form (for example, from a browser) in a controller
@ -2745,7 +2745,7 @@ To access multipart data sequentially, in streaming fashion, you can use `@Reque
[[webflux-ann-requestbody]]
==== `@RequestBody`
[.small]#<<web.adoc#mvc-ann-requestbody, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-ann-requestbody, Web MVC>>#
You can use the `@RequestBody` annotation to have the request body read and deserialized into an
`Object` through an <<webflux-codecs,HttpMessageReader>>.
@ -2819,7 +2819,7 @@ example uses a `BindingResult` argument`:
[[webflux-ann-httpentity]]
==== `HttpEntity`
[.small]#<<web.adoc#mvc-ann-httpentity, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-ann-httpentity, Web MVC>>#
`HttpEntity` is more or less identical to using <<webflux-ann-requestbody>> but is based on a
container object that exposes request headers and the body. The following example uses an
@ -2845,7 +2845,7 @@ container object that exposes request headers and the body. The following exampl
[[webflux-ann-responsebody]]
==== `@ResponseBody`
[.small]#<<web.adoc#mvc-ann-responsebody, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-ann-responsebody, Web MVC>>#
You can use the `@ResponseBody` annotation on a method to have the return serialized
to the response body through an <<webflux-codecs, HttpMessageWriter>>. The following
@ -2888,7 +2888,7 @@ configure or customize message writing.
[[webflux-ann-responseentity]]
==== `ResponseEntity`
[.small]#<<web.adoc#mvc-ann-responseentity, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-ann-responseentity, Web MVC>>#
`ResponseEntity` is like <<webflux-ann-responsebody>> but with status and headers. For example:
@ -2925,7 +2925,7 @@ Spring offers support for the Jackson JSON library.
[[webflux-ann-jsonview]]
===== JSON Views
[.small]#<<web.adoc#mvc-ann-jackson, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-ann-jackson, Web MVC>>#
Spring WebFlux provides built-in support for
https://www.baeldung.com/jackson-json-view-annotation[Jackson's Serialization Views],
@ -3003,7 +3003,7 @@ controller method. Use a composite interface if you need to activate multiple vi
[[webflux-ann-modelattrib-methods]]
=== `Model`
[.small]#<<web.adoc#mvc-ann-modelattrib-methods, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-ann-modelattrib-methods, Web MVC>>#
You can use the `@ModelAttribute` annotation:
@ -3142,7 +3142,7 @@ as the following example shows:
[[webflux-ann-initbinder]]
=== `DataBinder`
[.small]#<<web.adoc#mvc-ann-initbinder, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-ann-initbinder, Web MVC>>#
`@Controller` or `@ControllerAdvice` classes can have `@InitBinder` methods, to
initialize instances of `WebDataBinder`. Those, in turn, are used to:
@ -3237,7 +3237,7 @@ controller-specific `Formatter` instances, as the following example shows:
[[webflux-ann-controller-exceptions]]
=== Managing Exceptions
[.small]#<<web.adoc#mvc-ann-exceptionhandler, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-ann-exceptionhandler, Web MVC>>#
`@Controller` and <<mvc-ann-controller-advice, @ControllerAdvice>> classes can have
`@ExceptionHandler` methods to handle exceptions from controller methods. The following
@ -3298,7 +3298,7 @@ for more detail.
[[webflux-ann-rest-exceptions]]
==== REST API exceptions
[.small]#<<web.adoc#mvc-ann-rest-exceptions, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-ann-rest-exceptions, Web MVC>>#
A common requirement for REST services is to include error details in the body of the
response. The Spring Framework does not automatically do so, because the representation
@ -3316,7 +3316,7 @@ an HTTP status code.
[[webflux-ann-controller-advice]]
=== Controller Advice
[.small]#<<web.adoc#mvc-ann-controller-advice, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-ann-controller-advice, Web MVC>>#
Typically, the `@ExceptionHandler`, `@InitBinder`, and `@ModelAttribute` methods apply
within the `@Controller` class (or class hierarchy) in which they are declared. If you
@ -3384,7 +3384,7 @@ include::webflux-functional.adoc[leveloffset=+1]
[[webflux-uri-building]]
== URI Links
[.small]#<<web.adoc#mvc-uri-building, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-uri-building, Web MVC>>#
This section describes various options available in the Spring Framework to prepare URIs.
@ -3397,7 +3397,7 @@ include::webflux-cors.adoc[leveloffset=+1]
[[webflux-web-security]]
== Web Security
[.small]#<<web.adoc#mvc-web-security, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-web-security, Web MVC>>#
The https://projects.spring.io/spring-security/[Spring Security] project provides support
for protecting web applications from malicious exploits. See the Spring Security
@ -3415,7 +3415,7 @@ include::webflux-view.adoc[leveloffset=+1]
[[webflux-caching]]
== HTTP Caching
[.small]#<<web.adoc#mvc-caching, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-caching, Web MVC>>#
HTTP caching can significantly improve the performance of a web application. HTTP caching
revolves around the `Cache-Control` response header and subsequent conditional request
@ -3431,7 +3431,7 @@ This section describes the HTTP caching related options available in Spring WebF
[[webflux-caching-cachecontrol]]
=== `CacheControl`
[.small]#<<web.adoc#mvc-caching-cachecontrol, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-caching-cachecontrol, Web MVC>>#
{api-spring-framework}/http/CacheControl.html[`CacheControl`] provides support for
configuring settings related to the `Cache-Control` header and is accepted as an argument
@ -3479,7 +3479,7 @@ use case-oriented approach that focuses on the common scenarios, as the followin
[[webflux-caching-etag-lastmodified]]
=== Controllers
[.small]#<<web.adoc#mvc-caching-etag-lastmodified, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-caching-etag-lastmodified, Web MVC>>#
Controllers can add explicit support for HTTP caching. We recommend doing so, since the
`lastModified` or `ETag` value for a resource needs to be calculated before it can be compared
@ -3576,7 +3576,7 @@ to 409 (PRECONDITION_FAILED) to prevent concurrent modification.
[[webflux-caching-static-resources]]
=== Static Resources
[.small]#<<web.adoc#mvc-caching-static-resources, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-caching-static-resources, Web MVC>>#
You should serve static resources with a `Cache-Control` and conditional response headers
for optimal performance. See the section on configuring <<webflux-config-static-resources>>.
@ -3586,7 +3586,7 @@ for optimal performance. See the section on configuring <<webflux-config-static-
[[webflux-config]]
== WebFlux Config
[.small]#<<web.adoc#mvc-config, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-config, Web MVC>>#
The WebFlux Java configuration declares the components that are required to process
requests with annotated controllers or functional endpoints, and it offers an API to
@ -3603,7 +3603,7 @@ gain full control over the configuration through the
[[webflux-config-enable]]
=== Enabling WebFlux Config
[.small]#<<web.adoc#mvc-config-enable, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-config-enable, Web MVC>>#
You can use the `@EnableWebFlux` annotation in your Java config, as the following example shows:
@ -3632,7 +3632,7 @@ available on the classpath -- for JSON, XML, and others.
[[webflux-config-customize]]
=== WebFlux config API
[.small]#<<web.adoc#mvc-config-customize, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-config-customize, Web MVC>>#
In your Java configuration, you can implement the `WebFluxConfigurer` interface,
as the following example shows:
@ -3663,7 +3663,7 @@ class WebConfig : WebFluxConfigurer {
[[webflux-config-conversion]]
=== Conversion, formatting
[.small]#<<web.adoc#mvc-config-conversion, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-config-conversion, Web MVC>>#
By default, formatters for `Number` and `Date` types are installed, including support for
the `@NumberFormat` and `@DateTimeFormat` annotations. Full support for the Joda-Time
@ -3706,7 +3706,7 @@ use `FormatterRegistrar` implementations.
[[webflux-config-validation]]
=== Validation
[.small]#<<web.adoc#mvc-config-validation, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-config-validation, Web MVC>>#
By default, if <<core.adoc#validation-beanvalidation-overview, Bean Validation>> is present
on the classpath (for example, the Hibernate Validator), the `LocalValidatorFactoryBean`
@ -3781,7 +3781,7 @@ mark it with `@Primary` in order to avoid conflict with the one declared in the
[[webflux-config-content-negotiation]]
=== Content Type Resolvers
[.small]#<<web.adoc#mvc-config-content-negotiation, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-config-content-negotiation, Web MVC>>#
You can configure how Spring WebFlux determines the requested media types for
`@Controller` instances from the request. By default, only the `Accept` header is checked,
@ -3819,7 +3819,7 @@ The following example shows how to customize the requested content type resoluti
[[webflux-config-message-codecs]]
=== HTTP message codecs
[.small]#<<web.adoc#mvc-config-message-converters, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-config-message-converters, Web MVC>>#
The following example shows how to customize how the request and response body are read and written:
@ -3870,7 +3870,7 @@ It also automatically registers the following well-known modules if they are det
[[webflux-config-view-resolvers]]
=== View Resolvers
[.small]#<<web.adoc#mvc-config-view-resolvers, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-config-view-resolvers, Web MVC>>#
The following example shows how to configure view resolution:
@ -4027,7 +4027,7 @@ See <<webflux-view>> for more on the view technologies that are integrated with
[[webflux-config-static-resources]]
=== Static Resources
[.small]#<<web.adoc#mvc-config-static-resources, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-config-static-resources, Web MVC>>#
This option provides a convenient way to serve static resources from a list of
{api-spring-framework}/core/io/Resource.html[`Resource`]-based locations.
@ -4142,7 +4142,7 @@ without versions -- for example, from `/jquery/jquery.min.js` to
[[webflux-config-path-matching]]
=== Path Matching
[.small]#<<web.adoc#mvc-config-path-matching, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-config-path-matching, Web MVC>>#
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.
@ -4200,7 +4200,7 @@ reliance on it.
[[webflux-config-advanced-java]]
=== Advanced Configuration Mode
[.small]#<<web.adoc#mvc-config-advanced-java, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-config-advanced-java, Web MVC>>#
`@EnableWebFlux` imports `DelegatingWebFluxConfiguration` that:
@ -4240,7 +4240,7 @@ the classpath.
[[webflux-http2]]
== HTTP/2
[.small]#<<web.adoc#mvc-http2, Same as in Spring MVC>>#
[.small]#<<web.adoc#mvc-http2, Web MVC>>#
Servlet 4 containers are required to support HTTP/2, and Spring Framework 5 is compatible
with Servlet API 4. From a programming model perspective, there is nothing specific that

View File

@ -1,6 +1,6 @@
[[mvc-cors]]
= CORS
[.small]#<<web-reactive.adoc#webflux-cors, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-cors, WebFlux>>#
Spring MVC lets you handle CORS (Cross-Origin Resource Sharing). This section
describes how to do so.
@ -10,7 +10,7 @@ describes how to do so.
[[mvc-cors-intro]]
== Introduction
[.small]#<<web-reactive.adoc#webflux-cors-intro, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-cors-intro, WebFlux>>#
For security reasons, browsers prohibit AJAX calls to resources outside the current origin.
For example, you could have your bank account in one tab and evil.com in another. Scripts
@ -27,7 +27,7 @@ powerful workarounds based on IFRAME or JSONP.
[[mvc-cors-processing]]
== Processing
[.small]#<<web-reactive.adoc#webflux-cors-processing, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-cors-processing, WebFlux>>#
The CORS specification distinguishes between preflight, simple, and actual requests.
To learn how CORS works, you can read
@ -77,7 +77,7 @@ To learn more from the source or make advanced customizations, check the code be
[[mvc-cors-controller]]
== `@CrossOrigin`
[.small]#<<web-reactive.adoc#webflux-cors-controller, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-cors-controller, WebFlux>>#
The {api-spring-framework}/web/bind/annotation/CrossOrigin.html[`@CrossOrigin`]
annotation enables cross-origin requests on annotated controller methods,
@ -224,7 +224,7 @@ as the following example shows:
[[mvc-cors-global]]
== Global Configuration
[.small]#<<web-reactive.adoc#webflux-cors-global, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-cors-global, WebFlux>>#
In addition to fine-grained, controller method level configuration, you probably want to
define some global CORS configuration, too. You can set URL-based `CorsConfiguration`
@ -248,7 +248,7 @@ should only be used where appropriate.
[[mvc-cors-global-java]]
=== Java Configuration
[.small]#<<web-reactive.adoc#webflux-cors-global, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-cors-global, WebFlux>>#
To enable CORS in the MVC Java config, you can use the `CorsRegistry` callback,
as the following example shows:
@ -325,7 +325,7 @@ as the following example shows:
[[mvc-cors-filter]]
== CORS Filter
[.small]#<<web-reactive.adoc#webflux-cors-webfilter, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-cors-webfilter, WebFlux>>#
You can apply CORS support through the built-in
{api-spring-framework}/web/filter/CorsFilter.html[`CorsFilter`].

View File

@ -1,6 +1,6 @@
[[webmvc-fn]]
= Functional Endpoints
[.small]#<<web-reactive.adoc#webflux-fn, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-fn, WebFlux>>#
Spring Web MVC includes WebMvc.fn, a lightweight functional programming model in which functions
are used to route and handle requests and contracts are designed for immutability.
@ -12,7 +12,7 @@ the same <<web#mvc-servlet>>.
[[webmvc-fn-overview]]
== Overview
[.small]#<<web-reactive.adoc#webflux-fn-overview, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-fn-overview, WebFlux>>#
In WebMvc.fn, an HTTP request is handled with a `HandlerFunction`: a function that takes
`ServerRequest` and returns a `ServerResponse`.
@ -110,7 +110,7 @@ If you register the `RouterFunction` as a bean, for instance by exposing it in a
[[webmvc-fn-handler-functions]]
== HandlerFunction
[.small]#<<web-reactive.adoc#webflux-fn-handler-functions, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-fn-handler-functions, WebFlux>>#
`ServerRequest` and `ServerResponse` are immutable interfaces that offer JDK 8-friendly
access to the HTTP request and response, including headers, body, method, and status code.
@ -375,7 +375,7 @@ See <<core.adoc#validation-beanvalidation, Spring Validation>>.
[[webmvc-fn-router-functions]]
== `RouterFunction`
[.small]#<<web-reactive.adoc#webflux-fn-router-functions, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-fn-router-functions, WebFlux>>#
Router functions are used to route the requests to the corresponding `HandlerFunction`.
Typically, you do not write router functions yourself, but rather use a method on the
@ -581,7 +581,7 @@ We can further improve by using the `nest` method together with `accept`:
[[webmvc-fn-running]]
== Running a Server
[.small]#<<web-reactive.adoc#webflux-fn-running, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-fn-running, WebFlux>>#
You typically run router functions in a <<web.adoc#mvc-servlet, `DispatcherHandler`>>-based setup through the
<<web.adoc#mvc-config>>, which uses Spring configuration to declare the
@ -674,7 +674,7 @@ The following example shows a WebFlux Java configuration:
[[webmvc-fn-handler-filter-function]]
== Filtering Handler Functions
[.small]#<<web-reactive.adoc#webflux-fn-handler-filter-function, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-fn-handler-filter-function, WebFlux>>#
You can filter handler functions by using the `before`, `after`, or `filter` methods on the routing
function builder.

View File

@ -1,6 +1,6 @@
[[mvc-view]]
= View Technologies
[.small]#<<web-reactive.adoc#webflux-view, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-view, WebFlux>>#
The use of view technologies in Spring MVC is pluggable, whether you decide to use
Thymeleaf, Groovy Markup Templates, JSPs, or other technologies, is primarily a matter
@ -12,7 +12,7 @@ Spring MVC. We assume you are already familiar with <<mvc-viewresolver>>.
[[mvc-view-thymeleaf]]
== Thymeleaf
[.small]#<<web-reactive.adoc#webflux-view-thymeleaf, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-view-thymeleaf, WebFlux>>#
Thymeleaf is a modern server-side Java template engine that emphasizes natural HTML
templates that can be previewed in a browser by double-clicking, which is very helpful
@ -32,7 +32,7 @@ See https://www.thymeleaf.org/documentation.html[Thymeleaf+Spring] for more deta
[[mvc-view-freemarker]]
== FreeMarker
[.small]#<<web-reactive.adoc#webflux-view-freemarker, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-view-freemarker, WebFlux>>#
https://freemarker.apache.org/[Apache FreeMarker] is a template engine for generating any
kind of text output from HTML to email and others. The Spring Framework has built-in
@ -42,7 +42,7 @@ integration for using Spring MVC with FreeMarker templates.
[[mvc-view-freemarker-contextconfig]]
=== View Configuration
[.small]#<<web-reactive.adoc#webflux-view-freemarker-contextconfig, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-view-freemarker-contextconfig, WebFlux>>#
The following example shows how to configure FreeMarker as a view technology:
@ -123,7 +123,7 @@ returns a view name of `welcome`, the resolver looks for the
[[mvc-views-freemarker]]
=== FreeMarker Configuration
[.small]#<<web-reactive.adoc#webflux-views-freemarker, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-views-freemarker, WebFlux>>#
You can pass FreeMarker 'Settings' and 'SharedVariables' directly to the FreeMarker
`Configuration` object (which is managed by Spring) by setting the appropriate bean
@ -162,7 +162,7 @@ with additional convenience macros for generating form input elements themselves
[[mvc-view-bind-macros]]
==== The Bind Macros
[.small]#<<web-reactive.adoc#webflux-view-bind-macros, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-view-bind-macros, WebFlux>>#
A standard set of macros are maintained within the `spring-webmvc.jar` file for
FreeMarker, so they are always available to a suitably configured application.
@ -574,7 +574,7 @@ syntax. The following example shows a sample template for an HTML page:
[[mvc-view-script]]
== Script Views
[.small]#<<web-reactive.adoc#webflux-view-script, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-view-script, WebFlux>>#
The Spring Framework has a built-in integration for using Spring MVC with any
templating library that can run on top of the
@ -600,7 +600,7 @@ TIP: The basic rule for integrating any other script engine is that it must impl
[[mvc-view-script-dependencies]]
=== Requirements
[.small]#<<web-reactive.adoc#webflux-view-script-dependencies, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-view-script-dependencies, WebFlux>>#
You need to have the script engine on your classpath, the details of which vary by script engine:
@ -620,7 +620,7 @@ through https://www.webjars.org/[WebJars].
[[mvc-view-script-integrate]]
=== Script Templates
[.small]#<<web-reactive.adoc#webflux-script-integrate, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-script-integrate, WebFlux>>#
You can declare a `ScriptTemplateConfigurer` bean to specify the script engine to use,
the script files to load, what function to call to render templates, and so on.
@ -2020,7 +2020,7 @@ an external definition (by name) or as a `View` instance from the handler method
[[mvc-view-jackson]]
== Jackson
[.small]#<<web-reactive.adoc#webflux-view-httpmessagewriter, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-view-httpmessagewriter, WebFlux>>#
Spring offers support for the Jackson JSON library.
@ -2028,7 +2028,7 @@ Spring offers support for the Jackson JSON library.
[[mvc-view-json-mapping]]
=== Jackson-based JSON MVC Views
[.small]#<<web-reactive.adoc#webflux-view-httpmessagewriter, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-view-httpmessagewriter, WebFlux>>#
The `MappingJackson2JsonView` uses the Jackson library's `ObjectMapper` to render the response
content as JSON. By default, the entire contents of the model map (with the exception of
@ -2047,7 +2047,7 @@ serializers and deserializers for specific types.
[[mvc-view-xml-mapping]]
=== Jackson-based XML Views
[.small]#<<web-reactive.adoc#webflux-view-httpmessagewriter, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-view-httpmessagewriter, WebFlux>>#
`MappingJackson2XmlView` uses the
https://github.com/FasterXML/jackson-dataformat-xml[Jackson XML extension's] `XmlMapper`

View File

@ -23,7 +23,7 @@ https://github.com/spring-projects/spring-framework/wiki/Spring-Framework-Versio
[[mvc-servlet]]
== DispatcherServlet
[.small]#<<web-reactive.adoc#webflux-dispatcher-handler, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-dispatcher-handler, WebFlux>>#
Spring MVC, as many other web frameworks, is designed around the front controller
pattern where a central `Servlet`, the `DispatcherServlet`, provides a shared algorithm
@ -237,7 +237,7 @@ TIP: If an application context hierarchy is not required, applications may confi
[[mvc-servlet-special-bean-types]]
=== Special Bean Types
[.small]#<<web-reactive.adoc#webflux-special-bean-types, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-special-bean-types, WebFlux>>#
The `DispatcherServlet` delegates to special beans to process requests and render the
appropriate responses. By "`special beans`" we mean Spring-managed `Object` instances that
@ -297,7 +297,7 @@ The following table lists the special beans detected by the `DispatcherServlet`:
[[mvc-servlet-config]]
=== Web MVC Config
[.small]#<<web-reactive.adoc#webflux-framework-config, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-framework-config, WebFlux>>#
Applications can declare the infrastructure beans listed in <<mvc-servlet-special-bean-types>>
that are required to process requests. The `DispatcherServlet` checks the
@ -500,7 +500,7 @@ override the `createDispatcherServlet` method.
[[mvc-servlet-sequence]]
=== Processing
[.small]#<<web-reactive.adoc#webflux-dispatcher-handler-sequence, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-dispatcher-handler-sequence, WebFlux>>#
The `DispatcherServlet` processes requests as follows:
@ -610,7 +610,7 @@ declare it as an <<mvc-ann-controller-advice>> bean or configure it directly on
[[mvc-exceptionhandlers]]
=== Exceptions
[.small]#<<web-reactive.adoc#webflux-dispatcher-exceptions, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-dispatcher-exceptions, WebFlux>>#
If an exception occurs during request mapping or is thrown from a request handler (such as
a `@Controller`), the `DispatcherServlet` delegates to a chain of `HandlerExceptionResolver`
@ -721,7 +721,7 @@ however, use both a `WebApplicationInitializer` and a minimal `web.xml`.
[[mvc-viewresolver]]
=== View Resolution
[.small]#<<web-reactive.adoc#webflux-viewresolution, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-viewresolution, WebFlux>>#
Spring MVC defines the `ViewResolver` and `View` interfaces that let you render
models in a browser without tying you to a specific view technology. `ViewResolver`
@ -779,7 +779,7 @@ The following table provides more details on the `ViewResolver` hierarchy:
[[mvc-viewresolver-handling]]
==== Handling
[.small]#<<web-reactive.adoc#webflux-viewresolution-handling, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-viewresolution-handling, WebFlux>>#
You can chain view resolvers by declaring more than one resolver bean and, if necessary, by
setting the `order` property to specify ordering. Remember, the higher the order property,
@ -800,7 +800,7 @@ rendering without controller logic.
[[mvc-redirecting-redirect-prefix]]
==== Redirecting
[.small]#<<web-reactive.adoc#webflux-redirecting-redirect-prefix, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-redirecting-redirect-prefix, WebFlux>>#
The special `redirect:` prefix in a view name lets you perform a redirect. The
`UrlBasedViewResolver` (and its subclasses) recognize this as an instruction that a
@ -830,7 +830,7 @@ Servlet/JSP engine. Note that you may also chain multiple view resolvers, instea
[[mvc-multiple-representations]]
==== Content Negotiation
[.small]#<<web-reactive.adoc#webflux-multiple-representations, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-multiple-representations, WebFlux>>#
{api-spring-framework}/web/servlet/view/ContentNegotiatingViewResolver.html[`ContentNegotiatingViewResolver`]
does not resolve views itself but rather delegates
@ -1089,7 +1089,7 @@ request with a simple request parameter.
[[mvc-multipart]]
=== Multipart Resolver
[.small]#<<web-reactive.adoc#webflux-multipart, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-multipart, WebFlux>>#
`MultipartResolver` from the `org.springframework.web.multipart` package is a strategy
for parsing multipart requests including file uploads. There is one implementation
@ -1162,7 +1162,7 @@ Once the Servlet 3.0 configuration is in place, you can add a bean of type
[[mvc-logging]]
=== Logging
[.small]#<<web-reactive.adoc#webflux-logging, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-logging, WebFlux>>#
DEBUG-level logging in Spring MVC is designed to be compact, minimal, and
human-friendly. It focuses on high-value bits of information that are useful over and
@ -1178,7 +1178,7 @@ not meet the stated goals, please let us know.
[[mvc-logging-sensitive-data]]
==== Sensitive Data
[.small]#<<web-reactive.adoc#webflux-logging-sensitive-data, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-logging-sensitive-data, WebFlux>>#
DEBUG and TRACE logging may log sensitive information. This is why request parameters and
headers are masked by default and their logging in full must be enabled explicitly
@ -1242,7 +1242,7 @@ public class MyInitializer
[[filters]]
== Filters
[.small]#<<web-reactive.adoc#webflux-filters, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-filters, WebFlux>>#
The `spring-web` module provides some useful filters:
@ -1269,7 +1269,7 @@ available through the `ServletRequest.getParameter{asterisk}()` family of method
[[filters-forwarded-headers]]
=== Forwarded Headers
[.small]#<<web-reactive.adoc#webflux-forwarded-headers, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-forwarded-headers, WebFlux>>#
As a request goes through proxies (such as load balancers) the host, port, and
scheme may change, and that makes it a challenge to create links that point to the correct
@ -1330,7 +1330,7 @@ the filter via `web.xml` or in Spring Boot via a `FilterRegistrationBean` be sur
[[filters-cors]]
=== CORS
[.small]#<<web-reactive.adoc#webflux-filters-cors, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-filters-cors, WebFlux>>#
Spring MVC provides fine-grained support for CORS configuration through annotations on
controllers. However, when used with Spring Security, we advise relying on the built-in
@ -1343,7 +1343,7 @@ See the sections on <<mvc-cors>> and the <<mvc-cors-filter>> for more details.
[[mvc-controller]]
== Annotated Controllers
[.small]#<<web-reactive.adoc#webflux-controller, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-controller, WebFlux>>#
Spring MVC provides an annotation-based programming model where `@Controller` and
`@RestController` components use annotations to express request mappings, request input,
@ -1390,7 +1390,7 @@ programming model described in this section.
[[mvc-ann-controller]]
=== Declaration
[.small]#<<web-reactive.adoc#webflux-ann-controller, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-ann-controller, WebFlux>>#
You can define controller beans by using a standard Spring bean definition in the
Servlet's `WebApplicationContext`. The `@Controller` stereotype allows for auto-detection,
@ -1468,7 +1468,7 @@ change to `<tx:annotation-driven proxy-target-class="true"/>`, and with
[[mvc-ann-requestmapping]]
=== Request Mapping
[.small]#<<web-reactive.adoc#webflux-ann-requestmapping, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-ann-requestmapping, WebFlux>>#
You can use the `@RequestMapping` annotation to map requests to controllers methods. It has
various attributes to match by URL, HTTP method, request parameters, headers, and media
@ -1533,7 +1533,7 @@ The following example has type and method level mappings:
[[mvc-ann-requestmapping-uri-templates]]
==== URI patterns
[.small]#<<web-reactive.adoc#webflux-ann-requestmapping-uri-templates, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-ann-requestmapping-uri-templates, WebFlux>>#
You can map requests by using the following global patterns and wildcards:
@ -1633,7 +1633,7 @@ NOTE: Spring MVC uses the `PathMatcher` contract and the `AntPathMatcher` implem
[[mvc-ann-requestmapping-pattern-comparison]]
==== Pattern Comparison
[.small]#<<web-reactive.adoc#webflux-ann-requestmapping-pattern-comparison, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-ann-requestmapping-pattern-comparison, WebFlux>>#
When multiple patterns match a URL, they must be compared to find the best match. This is done
by using `AntPathMatcher.getPatternComparator(String path)`, which looks for patterns that are more
@ -1714,7 +1714,7 @@ recommendations related to RFD.
[[mvc-ann-requestmapping-consumes]]
==== Consumable Media Types
[.small]#<<web-reactive.adoc#webflux-ann-requestmapping-consumes, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-ann-requestmapping-consumes, WebFlux>>#
You can narrow the request mapping based on the `Content-Type` of the request,
as the following example shows:
@ -1752,7 +1752,7 @@ TIP: `MediaType` provides constants for commonly used media types, such as
[[mvc-ann-requestmapping-produces]]
==== Producible Media Types
[.small]#<<web-reactive.adoc#webflux-ann-requestmapping-produces, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-ann-requestmapping-produces, WebFlux>>#
You can narrow the request mapping based on the `Accept` request header and the list of
content types that a controller method produces, as the following example shows:
@ -1792,7 +1792,7 @@ TIP: `MediaType` provides constants for commonly used media types, such as
[[mvc-ann-requestmapping-params-and-headers]]
==== Parameters, headers
[.small]#<<web-reactive.adoc#webflux-ann-requestmapping-params-and-headers, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-ann-requestmapping-params-and-headers, WebFlux>>#
You can narrow request mappings based on request parameter conditions. You can test for the
presence of a request parameter (`myParam`), for the absence of one (`!myParam`), or for a
@ -1846,7 +1846,7 @@ instead.
[[mvc-ann-requestmapping-head-options]]
==== HTTP HEAD, OPTIONS
[.small]#<<web-reactive.adoc#webflux-ann-requestmapping-head-options, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-ann-requestmapping-head-options, WebFlux>>#
`@GetMapping` (and `@RequestMapping(method=HttpMethod.GET)`) support HTTP HEAD
transparently for request mapping. Controller methods do not need to change.
@ -1872,7 +1872,7 @@ is not necessary in the common case.
[[mvc-ann-requestmapping-composed]]
==== Custom Annotations
[.small]#<<web-reactive.adoc#mvc-ann-requestmapping-head-options, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#mvc-ann-requestmapping-head-options, WebFlux>>#
Spring MVC supports the use of <<core.adoc#beans-meta-annotations, composed annotations>>
for request mapping. Those are annotations that are themselves meta-annotated with
@ -1893,7 +1893,7 @@ you can check the custom attribute and return your own `RequestCondition`.
[[mvc-ann-requestmapping-registration]]
==== Explicit Registrations
[.small]#<<web-reactive.adoc#webflux-ann-requestmapping-registration, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-ann-requestmapping-registration, WebFlux>>#
You can programmatically register handler methods, which you can use for dynamic
registrations or for advanced cases, such as different instances of the same handler
@ -1946,7 +1946,7 @@ under different URLs. The following example registers a handler method:
[[mvc-ann-methods]]
=== Handler Methods
[.small]#<<web-reactive.adoc#webflux-ann-methods, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-ann-methods, WebFlux>>#
`@RequestMapping` handler methods have a flexible signature and can choose from a range of
supported controller method arguments and return values.
@ -1954,7 +1954,7 @@ supported controller method arguments and return values.
[[mvc-ann-arguments]]
==== Method Arguments
[.small]#<<web-reactive.adoc#webflux-ann-arguments, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-ann-arguments, WebFlux>>#
The next table describes the supported controller method arguments. Reactive types are not supported
for any arguments.
@ -2089,7 +2089,7 @@ and others) and is equivalent to `required=false`.
[[mvc-ann-return-types]]
==== Return Values
[.small]#<<web-reactive.adoc#webflux-ann-return-types, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-ann-return-types, WebFlux>>#
The next table describes the supported controller method return values. Reactive types are
supported for all return values.
@ -2190,7 +2190,7 @@ supported for all return values.
[[mvc-ann-typeconversion]]
==== Type Conversion
[.small]#<<web-reactive.adoc#webflux-ann-typeconversion, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-ann-typeconversion, WebFlux>>#
Some annotated controller method arguments that represent `String`-based request input (such as
`@RequestParam`, `@RequestHeader`, `@PathVariable`, `@MatrixVariable`, and `@CookieValue`)
@ -2205,7 +2205,7 @@ See <<core.adoc#format, Spring Field Formatting>>.
[[mvc-ann-matrix-variables]]
==== Matrix Variables
[.small]#<<web-reactive.adoc#webflux-ann-matrix-variables, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-ann-matrix-variables, WebFlux>>#
https://tools.ietf.org/html/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
@ -2345,7 +2345,7 @@ you need to set a `UrlPathHelper` with `removeSemicolonContent=false` through
[[mvc-ann-requestparam]]
==== `@RequestParam`
[.small]#<<web-reactive.adoc#webflux-ann-requestparam, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-ann-requestparam, WebFlux>>#
You can use the `@RequestParam` annotation to bind Servlet request parameters (that is,
query parameters or form data) to a method argument in a controller.
@ -2421,7 +2421,7 @@ with `@RequestParam`.
[[mvc-ann-requestheader]]
==== `@RequestHeader`
[.small]#<<web-reactive.adoc#webflux-ann-requestheader, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-ann-requestheader, WebFlux>>#
You can use the `@RequestHeader` annotation to bind a request header to a method argument in a
controller.
@ -2482,7 +2482,7 @@ example, a method parameter annotated with `@RequestHeader("Accept")` can be of
[[mvc-ann-cookievalue]]
==== `@CookieValue`
[.small]#<<web-reactive.adoc#webflux-ann-cookievalue, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-ann-cookievalue, WebFlux>>#
You can use the `@CookieValue` annotation to bind the value of an HTTP cookie to a method argument
in a controller.
@ -2522,7 +2522,7 @@ See <<mvc-ann-typeconversion>>.
[[mvc-ann-modelattrib-method-args]]
==== `@ModelAttribute`
[.small]#<<web-reactive.adoc#webflux-ann-modelattrib-method-args, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-ann-modelattrib-method-args, WebFlux>>#
You can use the `@ModelAttribute` annotation on a method argument to access an attribute from
the model or have it be instantiated if not present. The model attribute is also overlain with
@ -2701,7 +2701,7 @@ with `@ModelAttribute`.
[[mvc-ann-sessionattributes]]
==== `@SessionAttributes`
[.small]#<<web-reactive.adoc#webflux-ann-sessionattributes, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-ann-sessionattributes, WebFlux>>#
`@SessionAttributes` is used to store model attributes in the HTTP Servlet session between
requests. It is a type-level annotation that declares the session attributes used by a
@ -2786,7 +2786,7 @@ class EditPetForm {
[[mvc-ann-sessionattribute]]
==== `@SessionAttribute`
[.small]#<<web-reactive.adoc#webflux-ann-sessionattribute, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-ann-sessionattribute, WebFlux>>#
If you need access to pre-existing session attributes that are managed globally
(that is, outside the controller -- for example, by a filter) and may or may not be present,
@ -2823,7 +2823,7 @@ workflow, consider using `@SessionAttributes` as described in
[[mvc-ann-requestattrib]]
==== `@RequestAttribute`
[.small]#<<web-reactive.adoc#webflux-ann-requestattrib, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-ann-requestattrib, WebFlux>>#
Similar to `@SessionAttribute`, you can use the `@RequestAttribute` annotations to
access pre-existing request attributes created earlier (for example, by a Servlet `Filter`
@ -2950,7 +2950,7 @@ Therefore, we recommend that you use flash attributes mainly for redirect scenar
[[mvc-multipart-forms]]
==== Multipart
[.small]#<<web-reactive.adoc#webflux-multipart-forms, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-multipart-forms, WebFlux>>#
After a `MultipartResolver` has been <<mvc-multipart,enabled>>, the content of POST
requests with `multipart/form-data` is parsed and accessible as regular request
@ -3135,7 +3135,7 @@ as the following example shows:
[[mvc-ann-requestbody]]
==== `@RequestBody`
[.small]#<<web-reactive.adoc#webflux-ann-requestbody, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-ann-requestbody, WebFlux>>#
You can use the `@RequestBody` annotation to have the request body read and deserialized into an
`Object` through an <<integration.adoc#rest-message-conversion, `HttpMessageConverter`>>.
@ -3189,7 +3189,7 @@ as the following example shows:
[[mvc-ann-httpentity]]
==== HttpEntity
[.small]#<<web-reactive.adoc#webflux-ann-httpentity, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-ann-httpentity, WebFlux>>#
`HttpEntity` is more or less identical to using <<mvc-ann-requestbody>> but is based on a
container object that exposes request headers and body. The following listing shows an example:
@ -3215,7 +3215,7 @@ container object that exposes request headers and body. The following listing sh
[[mvc-ann-responsebody]]
==== `@ResponseBody`
[.small]#<<web-reactive.adoc#webflux-ann-responsebody, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-ann-responsebody, WebFlux>>#
You can use the `@ResponseBody` annotation on a method to have the return serialized
to the response body through an
@ -3257,7 +3257,7 @@ See <<mvc-ann-jackson>> for details.
[[mvc-ann-responseentity]]
==== ResponseEntity
[.small]#<<web-reactive.adoc#webflux-ann-responseentity, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-ann-responseentity, WebFlux>>#
`ResponseEntity` is like <<mvc-ann-responsebody>> but with status and headers. For example:
@ -3294,7 +3294,7 @@ Spring offers support for the Jackson JSON library.
[[mvc-ann-jsonview]]
===== JSON Views
[.small]#<<web-reactive.adoc#webflux-ann-jsonview, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-ann-jsonview, WebFlux>>#
Spring MVC provides built-in support for
https://www.baeldung.com/jackson-json-view-annotation[Jackson's Serialization Views],
@ -3403,7 +3403,7 @@ to the model, as the following example shows:
[[mvc-ann-modelattrib-methods]]
=== Model
[.small]#<<web-reactive.adoc#webflux-ann-modelattrib-methods, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-ann-modelattrib-methods, WebFlux>>#
You can use the `@ModelAttribute` annotation:
@ -3501,7 +3501,7 @@ unless the return value is a `String` that would otherwise be interpreted as a v
[[mvc-ann-initbinder]]
=== `DataBinder`
[.small]#<<web-reactive.adoc#webflux-ann-initbinder, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-ann-initbinder, WebFlux>>#
`@Controller` or `@ControllerAdvice` classes can have `@InitBinder` methods that
initialize instances of `WebDataBinder`, and those, in turn, can:
@ -3595,7 +3595,7 @@ controller-specific `Formatter` implementations, as the following example shows:
[[mvc-ann-exceptionhandler]]
=== Exceptions
[.small]#<<web-reactive.adoc#webflux-ann-controller-exceptions, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-ann-controller-exceptions, WebFlux>>#
`@Controller` and <<mvc-ann-controller-advice, @ControllerAdvice>> classes can have
`@ExceptionHandler` methods to handle exceptions from controller methods, as the following example shows:
@ -3844,7 +3844,7 @@ level, <<mvc-exceptionhandlers, HandlerExceptionResolver>> mechanism.
[[mvc-ann-rest-exceptions]]
==== REST API exceptions
[.small]#<<web-reactive.adoc#webflux-ann-rest-exceptions, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-ann-rest-exceptions, WebFlux>>#
A common requirement for REST services is to include error details in the body of the
response. The Spring Framework does not automatically do this because the representation
@ -3865,7 +3865,7 @@ necessary methods, and declare it as a Spring bean.
[[mvc-ann-controller-advice]]
=== Controller Advice
[.small]#<<web-reactive.adoc#webflux-ann-controller-advice, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-ann-controller-advice, WebFlux>>#
Typically `@ExceptionHandler`, `@InitBinder`, and `@ModelAttribute` methods apply within
the `@Controller` class (or class hierarchy) in which they are declared. If you want such
@ -3931,7 +3931,7 @@ include::webmvc-functional.adoc[leveloffset=+1]
[[mvc-uri-building]]
== URI Links
[.small]#<<web-reactive.adoc#webflux-uri-building, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-uri-building, WebFlux>>#
This section describes various options available in the Spring Framework to work with URI's.
@ -4400,7 +4400,7 @@ Spring WebFlux does support all that.
[[mvc-ann-async-http-streaming]]
=== HTTP Streaming
[.small]#<<web-reactive.adoc#webflux-codecs-streaming, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-codecs-streaming, WebFlux>>#
You can use `DeferredResult` and `Callable` for a single asynchronous return value.
What if you want to produce multiple asynchronous values and have those written to the
@ -4553,7 +4553,7 @@ customize the status and headers of the response.
[[mvc-ann-async-reactive-types]]
=== Reactive Types
[.small]#<<web-reactive.adoc#webflux-codecs-streaming, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-codecs-streaming, WebFlux>>#
Spring MVC supports use of reactive client libraries in a controller (also read
<<web-reactive.adoc#webflux-reactive-libraries, Reactive Libraries>> in the WebFlux section).
@ -4588,7 +4588,7 @@ suitable under load. If you plan to stream with a reactive type, you should use
[[mvc-ann-async-disconnects]]
=== Disconnects
[.small]#<<web-reactive.adoc#webflux-codecs-streaming, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-codecs-streaming, WebFlux>>#
The Servlet API does not provide any notification when a remote client goes away.
Therefore, while streaming to the response, whether through <<mvc-ann-async-sse, SseEmitter>>
@ -4656,7 +4656,7 @@ include::webmvc-cors.adoc[leveloffset=+1]
[[mvc-web-security]]
== Web Security
[.small]#<<web-reactive.adoc#webflux-web-security, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-web-security, WebFlux>>#
The https://projects.spring.io/spring-security/[Spring Security] project provides support
for protecting web applications from malicious exploits. See the Spring Security
@ -4674,7 +4674,7 @@ https://hdiv.org/[HDIV] is another web security framework that integrates with S
[[mvc-caching]]
== HTTP Caching
[.small]#<<web-reactive.adoc#webflux-caching, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-caching, WebFlux>>#
HTTP caching can significantly improve the performance of a web application. HTTP caching
revolves around the `Cache-Control` response header and, subsequently, conditional request
@ -4690,7 +4690,7 @@ This section describes the HTTP caching-related options that are available in Sp
[[mvc-caching-cachecontrol]]
=== `CacheControl`
[.small]#<<web-reactive.adoc#webflux-caching-cachecontrol, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-caching-cachecontrol, WebFlux>>#
{api-spring-framework}/http/CacheControl.html[`CacheControl`] provides support for
configuring settings related to the `Cache-Control` header and is accepted as an argument
@ -4746,7 +4746,7 @@ works as follows:
[[mvc-caching-etag-lastmodified]]
=== Controllers
[.small]#<<web-reactive.adoc#webflux-caching-etag-lastmodified, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-caching-etag-lastmodified, WebFlux>>#
Controllers can add explicit support for HTTP caching. We recommended doing so, since the
`lastModified` or `ETag` value for a resource needs to be calculated before it can be compared
@ -4843,7 +4843,7 @@ to 412 (PRECONDITION_FAILED), to prevent concurrent modification.
[[mvc-caching-static-resources]]
=== Static Resources
[.small]#<<web-reactive.adoc#webflux-caching-static-resources, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-caching-static-resources, WebFlux>>#
You should serve static resources with a `Cache-Control` and conditional response headers
for optimal performance. See the section on configuring <<mvc-config-static-resources>>.
@ -4863,7 +4863,7 @@ include::webmvc-view.adoc[leveloffset=+1]
[[mvc-config]]
== MVC Config
[.small]#<<web-reactive.adoc#webflux-config, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-config, WebFlux>>#
The MVC Java configuration and the MVC XML namespace provide default configuration
suitable for most applications and a configuration API to customize it.
@ -4879,7 +4879,7 @@ and <<mvc-servlet-config>>.
[[mvc-config-enable]]
=== Enable MVC Configuration
[.small]#<<web-reactive.adoc#webflux-config-enable, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-config-enable, WebFlux>>#
In Java configuration, you can use the `@EnableWebMvc` annotation to enable MVC
configuration, as the following example shows:
@ -4928,7 +4928,7 @@ available on the classpath (for example, payload converters for JSON, XML, and o
[[mvc-config-customize]]
=== MVC Config API
[.small]#<<web-reactive.adoc#webflux-config-customize, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-config-customize, WebFlux>>#
In Java configuration, you can implement the `WebMvcConfigurer` interface, as the
following example shows:
@ -4963,7 +4963,7 @@ sub-elements are available.
[[mvc-config-conversion]]
=== Type Conversion
[.small]#<<web-reactive.adoc#webflux-config-conversion, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-config-conversion, WebFlux>>#
By default formatters, for `Number` and `Date` types are installed, including support for
the `@NumberFormat` and `@DateTimeFormat` annotations. Full support for the Joda-Time
@ -5045,7 +5045,7 @@ FormatterRegistrar implementations.
[[mvc-config-validation]]
=== Validation
[.small]#<<web-reactive.adoc#webflux-config-validation, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-config-validation, WebFlux>>#
By default, if <<core.adoc#validation-beanvalidation-overview, Bean Validation>> is present
on the classpath (for example, Hibernate Validator), the `LocalValidatorFactoryBean` is
@ -5191,7 +5191,7 @@ The following example shows how to achieve the same configuration in XML:
[[mvc-config-content-negotiation]]
=== Content Types
[.small]#<<web-reactive.adoc#webflux-config-content-negotiation, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-config-content-negotiation, WebFlux>>#
You can configure how Spring MVC determines the requested media types from the request
(for example, `Accept` header, URL path extension, query parameter, and others).
@ -5257,7 +5257,7 @@ The following example shows how to achieve the same configuration in XML:
[[mvc-config-message-converters]]
=== Message Converters
[.small]#<<web-reactive.adoc#webflux-config-message-codecs, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-config-message-codecs, WebFlux>>#
You can customize `HttpMessageConverter` in Java configuration by overriding
{api-spring-framework}/web/servlet/config/annotation/WebMvcConfigurer.html#configureMessageConverters-java.util.List-[`configureMessageConverters()`]
@ -5403,7 +5403,7 @@ using the `<mvc:view-controller>` element:
[[mvc-config-view-resolvers]]
=== View Resolvers
[.small]#<<web-reactive.adoc#webflux-config-view-resolvers, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-config-view-resolvers, WebFlux>>#
The MVC configuration simplifies the registration of view resolvers.
@ -5523,7 +5523,7 @@ as the following example shows:
[[mvc-config-static-resources]]
=== Static Resources
[.small]#<<web-reactive.adoc#webflux-config-static-resources, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-config-static-resources, WebFlux>>#
This option provides a convenient way to serve static resources from a list of
{api-spring-framework}/core/io/Resource.html[`Resource`]-based locations.
@ -5754,7 +5754,7 @@ The following example shows how to achieve the same configuration in XML:
[[mvc-config-path-matching]]
=== Path Matching
[.small]#<<web-reactive.adoc#webflux-config-path-matching, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-config-path-matching, WebFlux>>#
You can customize options related to path matching and treatment of the URL.
For details on the individual options, see the
@ -5843,7 +5843,7 @@ The following example shows how to achieve the same configuration in XML:
[[mvc-config-advanced-java]]
=== Advanced Java Config
[.small]#<<web-reactive.adoc#webflux-config-advanced-java, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-config-advanced-java, WebFlux>>#
`@EnableWebMvc` imports `DelegatingWebMvcConfiguration`, which:
@ -5918,7 +5918,7 @@ by letting it be detected through a `<component-scan/>` declaration.
[[mvc-http2]]
== HTTP/2
[.small]#<<web-reactive.adoc#webflux-http2, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-http2, WebFlux>>#
Servlet 4 containers are required to support HTTP/2, and Spring Framework 5 is compatible
with Servlet API 4. From a programming model perspective, there is nothing specific that

View File

@ -1,7 +1,7 @@
[[websocket]]
= WebSockets
:doc-spring-security: {doc-root}/spring-security/site/docs/current/reference
[.small]#<<web-reactive.adoc#webflux-websocket, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-websocket, WebFlux>>#
This part of the reference documentation covers support for Servlet stack, WebSocket
messaging that includes raw WebSocket interactions, WebSocket emulation through SockJS, and
@ -14,7 +14,7 @@ include::websocket-intro.adoc[leveloffset=+1]
[[websocket-server]]
== WebSocket API
[.small]#<<web-reactive.adoc#webflux-websocket-server, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-websocket-server, WebFlux>>#
The Spring Framework provides a WebSocket API that you can use to write client- and
server-side applications that handle WebSocket messages.
@ -23,7 +23,7 @@ server-side applications that handle WebSocket messages.
[[websocket-server-handler]]
=== `WebSocketHandler`
[.small]#<<web-reactive.adoc#webflux-websocket-server-handler, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-websocket-server-handler, WebFlux>>#
Creating a WebSocket server is as simple as implementing `WebSocketHandler` or, more
likely, extending either `TextWebSocketHandler` or `BinaryWebSocketHandler`. The following
@ -112,7 +112,7 @@ sending. One option is to wrap the `WebSocketSession` with
[[websocket-server-handshake]]
=== WebSocket Handshake
[.small]#<<web-reactive.adoc#webflux-websocket-server-handshake, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-websocket-server-handshake, WebFlux>>#
The easiest way to customize the initial HTTP WebSocket handshake request is through
a `HandshakeInterceptor`, which exposes methods for "`before`" and "`after`" the handshake.
@ -258,7 +258,7 @@ Java initialization API. The following example shows how to do so:
[[websocket-server-runtime-configuration]]
=== Server Configuration
[.small]#<<web-reactive.adoc#webflux-websocket-server-config, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-websocket-server-config, WebFlux>>#
Each underlying WebSocket engine exposes configuration properties that control
runtime characteristics, such as the size of message buffer sizes, idle timeout,
@ -385,7 +385,7 @@ The following example shows the XML configuration equivalent of the preceding ex
[[websocket-server-allowed-origins]]
=== Allowed Origins
[.small]#<<web-reactive.adoc#webflux-websocket-server-cors, Same as in Spring WebFlux>>#
[.small]#<<web-reactive.adoc#webflux-websocket-server-cors, WebFlux>>#
As of Spring Framework 4.1.5, the default behavior for WebSocket and SockJS is to accept
only same-origin requests. It is also possible to allow all or a specified list of origins.