Skip to content

Commit

Permalink
doc(docs.reference.pages.web.servlet): add notes
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredo-toledano committed Jul 25, 2024
1 parent 092d11d commit 2acbef6
Showing 1 changed file with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
[[web.servlet]]
= Servlet Web Applications

If you want to build servlet-based web applications, you can take advantage of Spring Boot's auto-configuration for Spring MVC or Jersey.


* way to build servlet-based web applications
** Spring Boot's auto-configuration for
*** Spring MVC
*** Jersey

[[web.servlet.spring-mvc]]
== The "`Spring Web MVC Framework`"

The {url-spring-framework-docs}/web/webmvc.html[Spring Web MVC framework] (often referred to as "`Spring MVC`") is a rich "`model view controller`" web framework.
Spring MVC lets you create special `@Controller` or `@RestController` beans to handle incoming HTTP requests.
Methods in your controller are mapped to HTTP by using `@RequestMapping` annotations.

The following code shows a typical `@RestController` that serves JSON data:
* {url-spring-framework-docs}/web/webmvc.html[Spring Web MVC framework]
** -- oftenly referred to as -- "`Spring MVC`"
** == rich "`model view controller`" web framework
** allows
*** creating special `@Controller` or `@RestController` beans / handle incoming HTTP requests
**** controller's methods -- are mapped, via `@RequestMapping` to -- HTTP

include-code::MyRestController[]

Expand Down Expand Up @@ -86,21 +88,24 @@ When not configured, the following defaults are used:
[[web.servlet.spring-mvc.message-converters]]
=== HttpMessageConverters

Spring MVC uses the `HttpMessageConverter` interface to convert HTTP requests and responses.
Sensible defaults are included out of the box.
For example, objects can be automatically converted to JSON (by using the Jackson library) or XML (by using the Jackson XML extension, if available, or by using JAXB if the Jackson XML extension is not available).
By default, strings are encoded in `UTF-8`.

Any `HttpMessageConverter` bean that is present in the context is added to the list of converters.
You can also override default converters in the same way.

If you need to add or customize converters, you can use Spring Boot's `HttpMessageConverters` class, as shown in the following listing:
* provided by Spring MVC
* allows
** HTTP requests -- are converted in -- responses
** 👁️if a `HttpMessageConverter` bean / present | context -> is added to the list of converters 👁️
*** ALSO, you can override default converters

include-code::MyHttpMessageConvertersConfiguration[]
include-code::MyHttpMessageConvertersConfiguration[]

For further control, you can also sub-class `HttpMessageConverters` and override its `postProcessConverters` and/or `postProcessPartConverters` methods.
This can be useful when you want to re-order or remove some of the converters that Spring MVC configures by default.
** if you want to re-order or remove some converters / Spring MVC configures by default -> create sub-class `HttpMessageConverters` and override its `postProcessConverters` and/or `postProcessPartConverters` methods
*** _Example:_ TODO:

* existing defaults ones
** _Examples:_
*** objects -- via Jackson library, can be converted to -- JSON
*** objects -- via
**** Jackson XML extension, can be converted to -- XML
**** JAXB, can be converted to -- XML
*** String -- are encoded in -- `UTF-8`


[[web.servlet.spring-mvc.message-codes]]
Expand Down

0 comments on commit 2acbef6

Please sign in to comment.