How do you implement custom exception handling with Thymeleaf?
Throw custom exceptions, handle them in a @ControllerAdvice and render friendly Thymeleaf error pages in Spring Boot with correct status codes.
2,881 posts about Java: questions with answers, tutorials and articles, newest first.
Throw custom exceptions, handle them in a @ControllerAdvice and render friendly Thymeleaf error pages in Spring Boot with correct status codes.
@RequestMapping only routes requests in i18n. See how it combines with LocaleResolver, MessageSource and LocaleChangeInterceptor in Spring Boot.
Create per-language messages.properties files, configure spring.messages and a LocaleResolver, and read localized text with MessageSource in Spring Boot.
MessageSource resolves localised text by key and locale in Spring. See Spring Boot bundle setup, getMessage usage, implementations and localised validation messages.
Bind HTML forms to Java objects in Spring Boot with Thymeleaf: th:object, th:field, validation errors, Post/Redirect/Get and tips against mass assignment.
Build a Thymeleaf form in Spring Boot with th:object, th:field, Bean Validation errors and the Post/Redirect/Get pattern.
The Spring MVC Model interface carries named attributes from a controller to the view. Learn how to use it, how it differs from ModelAndView, and how redirects affect it.
Add attributes to the Model in a Spring Boot controller and read them in Thymeleaf with th:text and th:each. Covers ModelAndView, ModelAttribute and flash attributes.
th:text prints an expression result as the escaped body of an HTML element in Thymeleaf, protecting pages from XSS by default.
Add the Thymeleaf starter, return a view name from a controller and write an HTML template with th attributes, fragments and forms.
The Thymeleaf starter adds the template engine to Spring Boot and renders HTML files from src/main/resources/templates for your controllers.
Add the Thymeleaf starter to Spring Boot, render templates from controllers, reuse fragments, and build validated forms with CSRF support.
@Configuration turns a class into a source of Spring bean definitions. Learn @Bean methods, proxyBeanMethods, @Import and how it differs from @Component.
Define beans in a Spring Boot @Configuration class, bind application.yml values to a validated properties record and make beans conditional by profile or property.
Spring Boot merges settings from files, profiles, environment variables and command-line arguments. See the override order and how to bind values to typed beans.
@Slf4j generates a static SLF4J logger named log in your class at compile time. See Spring Boot setup, usage with placeholders and level configuration.
ResponseEntity represents the full HTTP response in Spring: status, headers and body. See when to use it and when a plain return type is enough.
Handle exceptions globally in Spring Boot with @RestControllerAdvice and @ExceptionHandler, returning consistent ProblemDetail error responses.
Use @ExceptionHandler to turn Spring validation failures into consistent 400 responses with per-field messages. Covers the exceptions that Spring 6.1 and later throw.
Validate request objects with Jakarta constraints and return consistent field-level 400 errors from one global exception handler.