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?
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?
As of Spring 5.3 in favor of implementing HandlerInterceptor and/or AsyncHandlerInterceptor directly.
So,
extends HandlerInterceptorAdapter -> implements HandlerInterceptor
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- https://docs.spring.io/spring-framework/docs/5.3.9/javadoc-api/org/springframework/web/servlet/HandlerInterceptor.html
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.
© 2022 - 2024 — McMap. All rights reserved.