From the course: Complete Guide to Spring MVC
Unlock this course with a free trial
Join today to access over 24,600 courses taught by industry experts.
Interceptors and handlers - Spring Tutorial
From the course: Complete Guide to Spring MVC
Interceptors and handlers
- [Instructor] Interceptors and handlers. Interceptors are components that allow pre-processing and post-processing of requests in Spring MVC. They are tied to the handler mapping and operate at specific points in the request lifecycle. So let's look at the PreHandle, PostHandle, and after completion aspects of the request lifecycle. PreHandle is invoked before the request is passed to the controller. PostHandle is called after the controller processes the request, but before the view is rendered. And AfterCompletion is executed after the response has been sent to the client and is ideal for cleanup. Let's look at creating and configuring interceptors. Here I've opened up IntelliJ. I've created a new class called custom interceptor, and here we're going to implement a custom interceptor. To implement a custom interceptor, you'll want to implement the handler interceptor interface, which you see after my class name I have implemented the handler interceptor in line 10. Next I've done…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.