1

I have implemented WebFilter for measuring roundtrip time of incoming request and to add MDC to context. is there a way to get this worked ?
Problem: WebFilter is not being called when i have both dependencies in my class path. if i remove spring-boot-starter-web , every thing works fine.

Dependency being used :

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
    <scope>compile</scope>
</dependency>
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-webflux</artifactId>
   </dependency>
<dependency>

Code Implemented:

import org.springframework.web.server.WebFilter    
@Component
public class RoundTrip implements WebFilter {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
        return chain.filter(exchange).doOnSuccess(r -> logWithContext(startTime));
    }
}
Akhil Bojedla
  • 1,968
  • 12
  • 19
santhoshgs
  • 13
  • 4
  • May I ask why do you have the `spring-boot-starter-web` in your dependencies? – Akhil Bojedla Jan 09 '20 at 16:41
  • We have other project dependency as lib/artifact in our project , which has spring-boot-starter-web as dependency. and for now we are not able to get rid of these dependency for now. – santhoshgs Jan 09 '20 at 17:01
  • it won't work since adding web dependency makes your application non-reactive by default - and it can only be reactive or traditional mvc app. See linked duplicate for details. – eis Jan 09 '20 at 17:16

0 Answers0