Spring boot 2.4.0 The type HandlerInterceptorAdapter is deprecated

After upgrade Spring boot version: 2.1.3.RELEASE -> 2.4.0

I got a warning:

The type HandlerInterceptorAdapter is deprecated 

Are there any replacements?

3 Answers

As of Spring 5.3 in favor of implementing HandlerInterceptor and/or AsyncHandlerInterceptor directly.

Spring doc

So,

extends HandlerInterceptorAdapter -> implements HandlerInterceptor 
1

However, Java 8 added the concept of default methods in interfaces. Naturally, the Spring team updated the framework to make full use of the new Java language features. Since Spring 5 with Java 8 baseline allows default methods, the adapter class HandlerInterceptorAdapter is no longer required. Now All the methods defined inside HandlerInterceptor are default methods-

Use instead

public class CustomHandlerInterceptor implements HandlerInterceptor{ // override default methods } 

Earlier - HandlerInterceptor and HandlerInterceptorAdapter In the first one we need to override all three methods: preHandle(), postHandle() and afterCompletion(), In the second we may implement only required methods.

Now in latest version , we can implement directly handlerInterceptor no need of adaptor we may implement only required methods.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like