title: Spring 5 Reactive - WebExceptionHandler is not getting called
body: <p>I have tried all 3 solutions suggested in <a href="https://stackoverflow.com/questions/43575538/what-is-the-right-way-to-handle-errors-in-spring-webflux/45280499#45280499">what is the right way to handle errors in spring-webflux</a>, but <code>WebExceptionHandler</code> is not getting called. I am using <code>Spring Boot 2.0.0.M7</code>. Github repo <a href="https://github.com/legendjaks/reflux" rel="nofollow noreferrer">here</a></p>
  
  <pre><code>@Configuration
  class RoutesConfiguration {
  
    @Autowired
    private lateinit var testService: TestService
  
    @Autowired
    private lateinit var globalErrorHandler: GlobalErrorHandler
  
    @Bean
    fun routerFunction():
  
      RouterFunction&lt;ServerResponse&gt; = router {
      ("/test").nest {
  
        GET("/") {
          ServerResponse.ok().body(testService.test())
        }
      }
    }
  
  
  } 
  
  
  @Component
  class GlobalErrorHandler() : WebExceptionHandler {
  
    companion object {
      private val log = LoggerFactory.getLogger(GlobalErrorHandler::class.java)
    }
  
    override fun handle(exchange: ServerWebExchange?, ex: Throwable?): Mono&lt;Void&gt; {
  
      log.info("inside handle")
  
      /* Handle different exceptions here */
      when(ex!!) {
        is ClientException -&gt; exchange!!.response.statusCode = HttpStatus.BAD_REQUEST
        is Exception -&gt; exchange!!.response.statusCode = HttpStatus.INTERNAL_SERVER_ERROR
      }
  
      return Mono.empty()
    }
  }
  </code></pre>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>When I change Spring Boot version to <code>2.0.0.M2</code>, the <code>WebExceptionHandler</code> is getting called. Do I need to do something for <code>2.0.0.M7</code>?</p>
  
  <p><strong>SOLUTION:</strong></p>
  
  <p>As per Brian's suggestion, it worked as</p>
  
  <pre><code>@Bean
  @Order(-2)
  fun globalErrorHandler() = GlobalErrorHandler()
  </code></pre>