What are the differences between Spring MVC and Spring WebFlux?
Spring MVC is blocking and servlet-based, WebFlux is reactive and non-blocking. See code, a comparison table and how virtual threads change the choice.
Spread Your Knowledge. Questions with answers, tutorials and articles, newest first.
Spring MVC is blocking and servlet-based, WebFlux is reactive and non-blocking. See code, a comparison table and how virtual threads change the choice.
Mono is the Reactor type for a single async result in Spring WebFlux. See controller usage, chaining, error handling and common pitfalls.
Learn to write a reactive REST controller in Spring WebFlux using Mono and Flux, functional routes, error handling, streaming and tests.
Build non-blocking Spring Boot services with WebFlux, Mono, Flux, R2DBC and WebClient, and learn when virtual threads with Spring MVC are the better fit.
@InitBinder lets a controller configure the WebDataBinder before request data is bound. See formatters, allowed fields, validators and ControllerAdvice examples.
Compare ConstraintValidator and Spring's Validator interface and build custom validators for fields, whole objects and services.
BindingResult holds binding and validation errors for a Spring MVC model object. Learn where it goes, how to use it, and how to show errors.
Learn four ways to customize Bean Validation messages in Spring: annotation attributes, properties files, MessageSource error codes and custom constraints.
@Valid tells Spring to run Jakarta Bean Validation on a request object and its nested fields. See how to set it up, handle errors and compare it with @Validated.
Annotate your form model, add @Valid with a BindingResult in the controller, and show field errors in Thymeleaf. Includes custom validators and central handling.
@ModelAttribute binds form and query parameters to a Java object and exposes it to the view in Spring MVC. See usage on parameters and methods.
Return objects as JSON in Spring MVC with @RestController, @ResponseBody and ResponseEntity, and control status codes, headers and serialisation.
@ResponseStatus changes the default 200 status of a Spring handler method. Learn 201 and 204 usage, exception handlers, pitfalls and testing.
Compare the four REST API versioning strategies in Spring and see working code for each, including the native version support added in Spring Framework 7.
@RequestMapping routes web requests to Spring controller methods by path, HTTP method, parameters, headers and media type. Learn its attributes and best practices.
Set up multiple message bundles in Spring Boot, resolve the user locale, switch languages with a request parameter and localise validation messages.
MessageSource resolves translated messages by code and locale in Spring. See how to configure bundles, pass arguments and avoid encoding problems.
Learn how Spring's MessageSource resolves translated text by code and locale, in web requests, services and background jobs.
@Controller returns view names for server-rendered pages, while @RestController writes return values straight to the response body, usually as JSON.
SecurityContextHolder is where Spring Security keeps the current user's Authentication. Learn how to read it, set it manually, and avoid common pitfalls.