Spring: HandlerInterceptor Example
In this section, we will learn about using Spring HandlerInterceptor in Spring Boot application. The Spring framework includes HandlerInterceptors, which are positioned in between DispatcherServlet and our Controllers. The primary purpose of interceptor is to intercept incoming request and response. It perform some operations on request and response. In Spring, an interceptor can be implemented by implementing HandlerInterceptor Interface. There are numerous uses for interceptors, some of which are mentioned below: 1. Logging Monitoring and troubleshooting running apps require logging. Using a combination of interceptors and Spring Boot's logging framework, we can log all requests, responses, and errors in a single location within an application. 2. Authentication & Authorization Incoming request can be intercepted by the Interceptor & authentication or authorization can be done, if denied then the request does not get delegated to the controller. 3. Request ...