Spring Boot handler interceptors: around every controller call
A HandlerInterceptor runs inside Spring MVC, after the controller method has been chosen, so it can read the method and its annotations. This page explains the callbacks, then runs them for successful, failing, blocked and asynchronous requests, and shows why a header set in postHandle sometimes never reaches the client.
Contents
What a handler interceptor is
A HandlerInterceptorDispatcherServlet@RestController
The interface has three methods, all with default implementations, so you override only the ones you need:
| Method | When it runs | Typical use |
|---|---|---|
preHandle | Before the handler; returning false | Access checks, rate limits, request context |
postHandle | After the handler returns normally, before the view is rendered | Adding model data for HTML views |
afterCompletion | After the response is complete, also after failures, for every interceptor whose preHandletrue | Timing, metrics, cleanup |
afterConcurrentHandlingStarted | In AsyncHandlerInterceptor | Releasing thread-bound state |
Interceptors and
- Position: filters run outside the
, interceptors inside it, after the handler has been chosen.DispatcherServlet - Information: an interceptor receives the handler. For a controller method it is a
, which gives the bean, theHandlerMethod and its annotations. A filter only sees the raw request.Method - Error handling: an exception thrown in
goes through Spring MVC's exception resolvers, sopreHandle methods can handle it. An exception in a filter cannot reach them.@ExceptionHandler - Scope: interceptors only see requests that Spring MVC handles. Requests rejected by a filter, such as Spring Security's, never reach them.
The examples use Spring Boot 4.1 with Spring Framework 7.0 and spring-boot-starter-webmvcWebMvcConfigurerafterCompletion
The life cycle of one request
One interceptor that prints each callback, and five requests that end differently, show when each method runs and when it does not. The requests succeed, fail with a handled exception, fail with an unhandled one, are blocked by preHandle
package demo.lifecycle;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.server.context.WebServerApplicationContext;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@SpringBootApplication
public class InterceptorLifecycle implements WebMvcConfigurer {
// Server-side lines are queued, because afterCompletion can run after the client
// already has its response; main prints them once the server has gone quiet.
static final BlockingQueue<String> LOG = new LinkedBlockingQueue<>();
static void log(String line) {
LOG.add(line);
}
static void printServerLog() throws InterruptedException {
String line;
while ((line = LOG.poll(300, TimeUnit.MILLISECONDS)) != null) {
System.out.println(line);
}
}
static class TracingInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
Object handler) {
String name = handler instanceof HandlerMethod m
? m.getBeanType().getSimpleName() + "." + m.getMethod().getName()
: handler.getClass().getSimpleName();
boolean allow = !request.getRequestURI().endsWith("/blocked");
log(" preHandle " + request.getDispatcherType() + " " + name + " -> " + allow);
if (!allow) {
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
}
return allow;
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response,
Object handler, ModelAndView modelAndView) {
log(" postHandle committed=" + response.isCommitted());
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response,
Object handler, Exception ex) {
log(" afterCompletion status=" + response.getStatus()
+ ", ex=" + (ex == null ? null : ex.getClass().getSimpleName()));
}
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new TracingInterceptor());
}
static class OutOfStockException extends RuntimeException {}
@RestController
static class ItemController {
@GetMapping("/items/{id}")
public String item(@PathVariable String id) {
log(" controller item(" + id + ")");
return switch (id) {
case "handled" -> throw new OutOfStockException();
case "unhandled" -> throw new IllegalStateException("bug");
default -> "item " + id;
};
}
@ExceptionHandler
public ResponseEntity<String> outOfStock(OutOfStockException e) {
return ResponseEntity.status(HttpStatus.CONFLICT).body("out of stock");
}
}
public static void main(String[] args) throws Exception {
try (var context = new SpringApplicationBuilder(InterceptorLifecycle.class)
.properties("server.port=0", "spring.main.banner-mode=off",
"logging.level.root=OFF")
.run(args)) {
int port = ((WebServerApplicationContext) context).getWebServer().getPort();
HttpClient http = HttpClient.newHttpClient();
for (String path : new String[] {"/items/7", "/items/handled", "/items/unhandled",
"/items/blocked", "/missing.txt"}) {
System.out.println("GET " + path);
HttpResponse<String> r = http.send(HttpRequest.newBuilder(
URI.create("http://localhost:" + port + path)).build(),
BodyHandlers.ofString());
printServerLog();
System.out.println(" client received " + r.statusCode());
}
}
}
}
GET /items/7
preHandle REQUEST ItemController.item -> true
controller item(7)
postHandle committed=true
afterCompletion status=200, ex=null
client received 200
GET /items/handled
preHandle REQUEST ItemController.item -> true
controller item(handled)
afterCompletion status=409, ex=null
client received 409
GET /items/unhandled
preHandle REQUEST ItemController.item -> true
controller item(unhandled)
afterCompletion status=200, ex=IllegalStateException
preHandle ERROR BasicErrorController.error -> true
postHandle committed=true
afterCompletion status=500, ex=null
client received 500
GET /items/blocked
preHandle REQUEST ItemController.item -> false
client received 403
GET /missing.txt
preHandle REQUEST ResourceHttpRequestHandler -> true
afterCompletion status=404, ex=null
preHandle ERROR BasicErrorController.error -> true
postHandle committed=true
afterCompletion status=404, ex=null
client received 404
- For
, all three callbacks ran in order around the controller. The handler was the/items/7 forHandlerMethod .ItemController.item - For
, the controller threw and its own/items/handled returned 409.@ExceptionHandler did not run, because the handler did not return normally.postHandle receivedafterCompletion , since the exception was resolved. An interceptor that counts failures from theex=null argument misses every handled exception; readex instead.response.getStatus() - For
,/items/unhandled received theafterCompletion , while the status was still 200. Tomcat then forwarded toIllegalStateException , and the interceptor ran a second time, with dispatcher type/error , aroundERROR .BasicErrorController.error - For
,/items/blocked set 403 and returnedpreHandle . Neither the controller nor any other callback of that interceptor ran.false - For
, the handler was a/missing.txt , Spring's handler for static files, not aResourceHttpRequestHandler . A cast toHandlerMethod without theHandlerMethod check would have throwninstanceof here.ClassCastException sawpostHandle in every case where it ran: the response had already been sent. The section on headers below shows why that matters.committed=true
Interceptors run on error dispatches by default, unlike Spring Boot's filter registrations. To skip them, exclude the error path with excludePathPatterns("/error")request.getDispatcherType()
Paths, order and annotations
Real applications register several interceptors with different scopes. Here an audit interceptor covers everything except the health check, and a role check covers only /admin/**@RequiresRole
package demo.order;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.server.context.WebServerApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@SpringBootApplication
public class OrderAndPaths implements WebMvcConfigurer {
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@interface RequiresRole {
String value();
}
static final BlockingQueue<String> LOG = new LinkedBlockingQueue<>();
// Prints every callback, so the nesting of two interceptors is visible
static class Named implements HandlerInterceptor {
final String name;
Named(String name) {
this.name = name;
}
@Override
public boolean preHandle(HttpServletRequest req, HttpServletResponse res, Object h)
throws Exception {
LOG.add(" " + name + ".preHandle");
return true;
}
@Override
public void postHandle(HttpServletRequest req, HttpServletResponse res, Object h,
ModelAndView mv) {
LOG.add(" " + name + ".postHandle");
}
@Override
public void afterCompletion(HttpServletRequest req, HttpServletResponse res,
Object h, Exception ex) {
LOG.add(" " + name + ".afterCompletion");
}
}
// Reads an annotation from the controller method that is about to run
static class RoleCheck extends Named {
RoleCheck() {
super("RoleCheck");
}
@Override
public boolean preHandle(HttpServletRequest req, HttpServletResponse res, Object h)
throws Exception {
super.preHandle(req, res, h);
if (h instanceof HandlerMethod method) {
RequiresRole rule = method.getMethodAnnotation(RequiresRole.class);
if (rule != null && !rule.value().equals(req.getHeader("X-Role"))) {
LOG.add(" RoleCheck rejects: needs " + rule.value());
res.setStatus(HttpServletResponse.SC_FORBIDDEN);
return false;
}
}
return true;
}
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new Named("Audit"))
.excludePathPatterns("/health")
.order(1);
registry.addInterceptor(new RoleCheck())
.addPathPatterns("/admin/**")
.order(2);
}
@RestController
static class Endpoints {
@GetMapping("/health")
public String health() {
LOG.add(" controller health");
return "up";
}
@GetMapping("/admin/users")
public String users() {
LOG.add(" controller users");
return "users";
}
@GetMapping("/admin/reports/{year}")
@RequiresRole("auditor")
public String report() {
LOG.add(" controller report");
return "report";
}
}
public static void main(String[] args) throws Exception {
try (var context = new SpringApplicationBuilder(OrderAndPaths.class)
.properties("server.port=0", "spring.main.banner-mode=off",
"logging.level.root=WARN")
.run(args)) {
int port = ((WebServerApplicationContext) context).getWebServer().getPort();
HttpClient http = HttpClient.newHttpClient();
String[][] calls = {{"/health", "-"}, {"/admin/users", "-"},
{"/admin/reports/2026", "-"}, {"/admin/reports/2026", "auditor"}};
for (String[] call : calls) {
System.out.println("GET " + call[0] + " X-Role: " + call[1]);
HttpResponse<String> r = http.send(HttpRequest.newBuilder(
URI.create("http://localhost:" + port + call[0]))
.header("X-Role", call[1]).build(), BodyHandlers.ofString());
String line;
while ((line = LOG.poll(300, TimeUnit.MILLISECONDS)) != null) {
System.out.println(line);
}
System.out.println(" client received " + r.statusCode());
}
}
}
}
GET /health X-Role: -
controller health
client received 200
GET /admin/users X-Role: -
Audit.preHandle
RoleCheck.preHandle
controller users
RoleCheck.postHandle
Audit.postHandle
RoleCheck.afterCompletion
Audit.afterCompletion
client received 200
GET /admin/reports/2026 X-Role: -
Audit.preHandle
RoleCheck.preHandle
RoleCheck rejects: needs auditor
Audit.afterCompletion
client received 403
GET /admin/reports/2026 X-Role: auditor
Audit.preHandle
RoleCheck.preHandle
controller report
RoleCheck.postHandle
Audit.postHandle
RoleCheck.afterCompletion
Audit.afterCompletion
client received 200
ran with no interceptor at all: the audit interceptor excludes it, and the role check only includes/health ./admin/**- For
, the/admin/users calls ran in registration order, Audit then RoleCheck, andpreHandle andpostHandle ran in reverse order. Interceptors nest like filters: the first in is the last out.afterCompletion - The users method has no
, so@RequiresRole returnedgetMethodAnnotation and the role check let the request through.null - The report method needs
. Without that role, RoleCheck set 403 and returnedauditor . Spring then calledfalse only on Audit, the interceptor whoseafterCompletion had already returnedpreHandle . RoleCheck's owntrue did not run.afterCompletion - With
, the full sequence ran again and the report was returned.X-Role: auditor
The path patterns use Spring's PathPattern/admin/**/admin/*{year}order()
Why headers set in postHandle can disappear
postHandle
package demo.posthandle;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.server.context.WebServerApplicationContext;
import org.springframework.core.MethodParameter;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
@SpringBootApplication
public class PostHandleHeaders implements WebMvcConfigurer {
static class HeaderInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest req, HttpServletResponse res, Object h) {
res.setHeader("X-Pre", "set in preHandle");
return true;
}
@Override
public void postHandle(HttpServletRequest req, HttpServletResponse res, Object h,
ModelAndView mv) {
LOG.add(" postHandle sees committed=" + res.isCommitted());
res.setHeader("X-Post", "set in postHandle");
}
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new HeaderInterceptor());
}
public record Price(String amount, String currency) {}
static final BlockingQueue<String> LOG = new LinkedBlockingQueue<>();
// Runs after the controller returns, but before the body is written
@RestControllerAdvice
static class EnvelopeAdvice implements ResponseBodyAdvice<Object> {
@Override
public boolean supports(MethodParameter returnType,
Class<? extends HttpMessageConverter<?>> converterType) {
return true;
}
@Override
public Object beforeBodyWrite(Object body, MethodParameter returnType,
MediaType contentType,
Class<? extends HttpMessageConverter<?>> converterType,
ServerHttpRequest request, ServerHttpResponse response) {
response.getHeaders().set("X-Advice", "set in ResponseBodyAdvice");
return body; // could also replace or wrap the body
}
}
@RestController
static class PriceController {
@GetMapping("/price")
public Price price() {
return new Price("12.50", "EUR");
}
@GetMapping("/text")
public String text() {
return "12.50 EUR";
}
@GetMapping("/big")
public Price big() {
return new Price("12.50", "EUR".repeat(4000)); // about 12 KB of JSON
}
}
public static void main(String[] args) throws Exception {
try (var context = new SpringApplicationBuilder(PostHandleHeaders.class)
.properties("server.port=0", "spring.main.banner-mode=off",
"logging.level.root=WARN")
.run(args)) {
int port = ((WebServerApplicationContext) context).getWebServer().getPort();
HttpClient http = HttpClient.newHttpClient();
for (String path : new String[] {"/price", "/text", "/big"}) {
HttpResponse<String> r = http.send(HttpRequest.newBuilder(
URI.create("http://localhost:" + port + path)).build(),
BodyHandlers.ofString());
System.out.println("GET " + path + " -> " + r.statusCode() + ", "
+ r.body().length() + " chars of " + r.headers()
.firstValue("Content-Type").orElse("?"));
String line;
while ((line = LOG.poll(300, TimeUnit.MILLISECONDS)) != null) {
System.out.println(line);
}
for (String h : new String[] {"X-Pre", "X-Advice", "X-Post"}) {
System.out.println(" " + h + ": "
+ r.headers().firstValue(h).orElse("(missing)"));
}
}
}
}
}
GET /price -> 200, 35 chars of application/json
postHandle sees committed=false
X-Pre: set in preHandle
X-Advice: set in ResponseBodyAdvice
X-Post: set in postHandle
GET /text -> 200, 9 chars of text/plain;charset=UTF-8
postHandle sees committed=true
X-Pre: set in preHandle
X-Advice: set in ResponseBodyAdvice
X-Post: (missing)
GET /big -> 200, 12032 chars of application/json
postHandle sees committed=true
X-Pre: set in preHandle
X-Advice: set in ResponseBodyAdvice
X-Post: (missing)
- The header from
arrived in all three responses, because nothing had been written when it was set.preHandle - The header from the
also arrived in all three.ResponseBodyAdvice runs after the controller returns and just before the converter writes the body, which is the right moment for headers that depend on the result. The same method can change or wrap the body.beforeBodyWrite - The header from
arrived only for the small JSON response, where the response was not yet committed. For the plain string, the string converter had already flushed the response. For the 12 KB JSON, the body was larger than Tomcat's 8 KB output buffer, so part of it, with the headers, had already been sent.postHandle
The result depends on the converter and on the size of the body, so code that works in a test with a small response can fail in production. For @ResponseBodypostHandlepreHandleResponseBodyAdvice
Asynchronous requests
A controller that returns a CompletableFutureDeferredResultCallable
package demo.async;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.server.context.WebServerApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.AsyncHandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@SpringBootApplication
public class AsyncRequests implements WebMvcConfigurer {
static final BlockingQueue<String> LOG = new LinkedBlockingQueue<>();
static class TimingInterceptor implements AsyncHandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest req, HttpServletResponse res, Object h) {
LOG.add(" preHandle " + req.getDispatcherType());
return true;
}
@Override
public void afterConcurrentHandlingStarted(HttpServletRequest req,
HttpServletResponse res, Object h) {
LOG.add(" afterConcurrentHandlingStarted " + req.getDispatcherType()
+ " (Tomcat thread is released)");
}
@Override
public void postHandle(HttpServletRequest req, HttpServletResponse res, Object h,
ModelAndView mv) {
LOG.add(" postHandle " + req.getDispatcherType());
}
@Override
public void afterCompletion(HttpServletRequest req, HttpServletResponse res,
Object h, Exception ex) {
LOG.add(" afterCompletion " + req.getDispatcherType());
}
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new TimingInterceptor());
}
@RestController
static class QuoteController {
@GetMapping("/quote")
public CompletableFuture<String> quote() {
LOG.add(" controller returns a future");
return CompletableFuture.supplyAsync(() -> {
LOG.add(" future completes on another thread");
return "EUR/USD 1.09";
}, CompletableFuture.delayedExecutor(500, TimeUnit.MILLISECONDS));
}
}
public static void main(String[] args) throws Exception {
try (var context = new SpringApplicationBuilder(AsyncRequests.class)
.properties("server.port=0", "spring.main.banner-mode=off",
"logging.level.root=WARN")
.run(args)) {
int port = ((WebServerApplicationContext) context).getWebServer().getPort();
HttpResponse<String> r = HttpClient.newHttpClient().send(HttpRequest.newBuilder(
URI.create("http://localhost:" + port + "/quote")).build(),
BodyHandlers.ofString());
System.out.println("GET /quote");
String line;
while ((line = LOG.poll(300, TimeUnit.MILLISECONDS)) != null) {
System.out.println(line);
}
System.out.println(" client received " + r.statusCode() + " " + r.body());
}
}
}
GET /quote
preHandle REQUEST
controller returns a future
afterConcurrentHandlingStarted REQUEST (Tomcat thread is released)
future completes on another thread
preHandle ASYNC
postHandle ASYNC
afterCompletion ASYNC
client received 200 EUR/USD 1.09
- On the first dispatch,
ran, the controller returned the future, and Spring calledpreHandle instead ofafterConcurrentHandlingStarted andpostHandle . The Tomcat thread then went back to the pool.afterCompletion - When the future completed, Spring dispatched the request again with type
to write the result.ASYNC ran a second time, followed bypreHandle andpostHandle .afterCompletion - Code in
that starts a timer or increments a counter therefore runs twice for one request. CheckpreHandle , or keep such code in arequest.getDispatcherType() , which skips the second dispatch by default.OncePerRequestFilter
Implement AsyncHandlerInterceptorpreHandleThreadLocalafterConcurrentHandlingStarted
Traps with interceptors
- Creating with new: an interceptor built with
innew is not a Spring bean, so it gets no injected dependencies. To inject services, declare it as a bean and pass the bean toaddInterceptors .addInterceptor - Replacing Spring Boot's MVC setup: adding
turns off Spring Boot's MVC auto-configuration, including its message converters and static resources. Implement@EnableWebMvc withoutWebMvcConfigurer to add interceptors.@EnableWebMvc - Static resources and CORS: interceptors also run for static files and for CORS preflight requests. A
that requires a login header rejects preflights, which browsers send without credentials; skip requests wherepreHandle is true.CorsUtils.isPreFlightRequest(request) - Returning false without a response:
that returnspreHandle without setting a status sends 200 with an empty body. Always set the status, and a body if the client needs one.false - Exceptions from preHandle: throwing is often cleaner than returning
, because the exception goes through yourfalse and produces the same error format as the rest of the API.@RestControllerAdvice
Choosing between interceptors, filters and advice
| Need | Use |
|---|---|
| Logic that depends on the controller method or its annotations | HandlerInterceptor.preHandle |
| Timing or metrics per handler | preHandleafterCompletionex |
Headers or body changes for @ResponseBody | ResponseBodyAdvice |
| Model attributes for HTML views | postHandle@ModelAttribute |
| Thread-bound state with async controllers | AsyncHandlerInterceptor |
| Every request, including ones Spring MVC never handles | A |
| Authentication | Spring Security |
| Turning exceptions into responses |
An interceptor is the right tool when the decision needs to know which controller method will run. For the controllers themselves, see