How do you implement custom error pages in Spring MVC?
Create custom 404 and 500 pages in Spring MVC and Spring Boot, map exceptions with @ControllerAdvice and return JSON problem details for APIs.
Spread Your Knowledge. Questions with answers, tutorials and articles, newest first.
Create custom 404 and 500 pages in Spring MVC and Spring Boot, map exceptions with @ControllerAdvice and return JSON problem details for APIs.
@Controller marks a class as a Spring MVC web controller whose mapped methods handle requests and usually return view names. Compare it with @RestController and see testing tips.
Define a messageSource bean or use spring.messages properties, add per-language files and a LocaleResolver, and resolve messages by locale in Spring.
LocaleResolver tells Spring MVC which Locale applies to each request. See the built-in resolvers, LocaleChangeInterceptor and MessageSource setup.
Configure a MessageSource, a LocaleResolver and a LocaleChangeInterceptor so a Spring web application can show text in the user's language.
Save new users as disabled, email a random expiring token, and enable the account on click. A Spring Boot 3 and Spring Security 6 example with hardening tips.
@EnableResourceServer belonged to retired Spring Security OAuth. Learn what it did and how to build a JWT resource server with Spring Security 6 today.
Define a JwtEncoder, JwtDecoder and a stateless SecurityFilterChain with oauth2ResourceServer. Includes login, roles claims and token security practices.
@EnableAuthorizationServer comes from the end-of-life Spring Security OAuth project. See what it did and how Spring Authorization Server replaces it.
@EnableGlobalMethodSecurity turns on method-level authorization in Spring Security. It is deprecated; see how @EnableMethodSecurity replaces it.
Enforce password rules at registration with a custom Bean Validation constraint, hash with a PasswordEncoder, and screen breached passwords using Spring Security 6.3.
Learn why Spring Security uses PasswordEncoder, how encode and matches work, which implementations to pick, and how to migrate hashes safely.
Configure logout in Spring Security 6 and 7 using the lambda DSL, with CSRF-safe POST logout, custom handlers, redirects and stateless JWT APIs.
@Secured guards Spring methods by required authorities. See how to enable it, the ROLE_ prefix rule, testing and when to use @PreAuthorize instead.
See how Spring Security 6 validates CSRF tokens, how to pick a token repository, exempt endpoints, disable protection safely and test it.
SecurityContextHolder gives your code access to the authenticated user's SecurityContext. Learn the storage strategies and how to propagate the context to other threads.
Enable @EnableMethodSecurity and secure service methods with @PreAuthorize and SpEL. Covers roles, authorities, filters and testing.
Compare basic and form-based authentication: how credentials travel, sessions, logout, security risks and when to use each, with Spring Security 6 code.
Create a custom UserDetailsService that loads users from a database and plug it into Spring Security 6 with a PasswordEncoder and SecurityFilterChain.
UserDetailsService loads a user by username and returns the hash and authorities. Spring Security then verifies the password.