'How to get in WebFlux / WebFilter method handler annotation

Is it optimal solution ? how we resolve it - get controller's method annotation (Kotlin)

     @Component
     class AuditWebFilter(
          private val requestMapping: RequestMappingHandlerMapping
     ): WebFilter {

          override fun filter(exchange: ServerWebExchange, chain: WebFilterChain): Mono<Void> {
               // if not to call - then exchange.attributes will be empty
               // so little early initialize exchange.attributes by calling next line
               requestMapping.getHandler(exchange)

               val handlerFunction = exchange.attributes.get(HandlerMapping.BEST_MATCHING_HANDLER_ATTRIBUTE) as HandlerMethod
               val annotationMethod = handlerFunction.method.getAnnotation(MyAnnotation::class.java)

               // annotationMethod  proccesing here
          }
     }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source