Spring boot 2.4.0 The type HandlerInterceptorAdapter is deprecated
Asked Answered
G

3

30

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?

Garnishee answered 4/12, 2020 at 2:10 Comment(0)
D
89

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

Spring doc

So,

extends HandlerInterceptorAdapter -> implements HandlerInterceptor
Determine answered 4/12, 2020 at 2:13 Comment(1)
the link is dead, I'm upgrading from srpring-boot 2.1.2 to 3.0.1 and bumping into issues importing org.springframework.web.servlet.handler.HandlerInterceptorAdapterFundamentalism
S
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- 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
}
Sightseeing answered 9/4, 2023 at 11:49 Comment(0)
B
-1

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.

Buttery answered 22/7, 2021 at 8:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.