What is the difference and usage between Spring Boot interceptor and filter
This article focuses on "what is the difference and usage between Spring Boot interceptor and filter". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let the editor take you to learn the difference and usage of Spring Boot interceptor and filter.
Before we talk about Spring boot, let's take a look at filters and interceptors. The two are very similar in function, but there is still a big gap in the specific technical implementation. Before analyzing the difference between the two, let's understand the concept of AOP. AOP is not a concrete technology, but a programming idea. In the process of object-oriented programming, it is easy to solve vertical expansion through inheritance and polymorphism. But for horizontal functions, such as opening transactions in all service methods, or logging uniformly, object-oriented cannot be solved. So AOP-- aspect-oriented programming is actually a supplement to the idea of object-oriented programming. The filters and interceptors we are talking about today are specific implementations of aspect-oriented programming. The main differences between the two include the following aspects:
1. Filter is dependent on the Servlet container and is part of the Servlet specification, while the interceptor exists independently and can be used in any case.
2. The execution of Filter is completed by the callback of the Servlet container, while the interceptor is usually executed by dynamic proxy.
3. The life cycle of Filter is managed by the Servlet container, while the interceptor can be managed through the IoC container, so you can obtain other Bean instances through injection, so it is more convenient to use.
At this point, I believe you have a deeper understanding of "what is the difference and usage between Spring Boot interceptor and filter". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!