title: Spring Cloud Gateway Custom Gateway Filter Not Working
body: <p>I'm trying to debug my application, but debugger not hitting this code block. Here is my custom gateway filter.</p>
  <pre><code>@RefreshScope
  @Component
  public class AuthorizationHeaderFilter extends 
             AbstractGatewayFilterFactory&lt;AuthorizationHeaderFilter.Config&gt; {
  
  @Autowired
  Environment environment;
  
  public AuthorizationHeaderFilter () {
      super(Config.class);
  }
  
  public static class Config {
  }
  
  @Override
  public GatewayFilter apply(Config config) {
      return ((exchange, chain) -&gt; {
  
          ServerHttpRequest request = exchange.getRequest();
  
          if(!request.getHeaders().containsKey(HttpHeaders.AUTHORIZATION)) {
              return onError(exchange, &quot;No authorization header&quot;, HttpStatus.UNAUTHORIZED);
          }
  
          String token = Objects.requireNonNull(request.getHeaders().get(HttpHeaders.AUTHORIZATION))
                  .get(0).replace(&quot;Bearer&quot;,&quot;&quot;);
  
          if(isJwtValid(token))
              return onError(exchange, &quot;JWT Token is not valid&quot;, HttpStatus.UNAUTHORIZED);
  
          return chain.filter(exchange);
      });
  }
  
  private Mono&lt;Void&gt; onError(ServerWebExchange exchange, String error, HttpStatus status) {
      ServerHttpResponse response = exchange.getResponse();
  
      response.setStatusCode(status);
      return response.setComplete();
  }
  
  private boolean isJwtValid(String token) {
      boolean returnValue = true;
  
      String subject = Jwts.parser().setSigningKey(environment.getProperty(&quot;token.secret&quot;)).parseClaimsJws(token)
              .getBody().getSubject();
  
      if(subject == null || subject.isEmpty())
          returnValue = false;
  
      return returnValue;
  }
  }
  </code></pre>
  <p>And here is the configuration for this filter</p>
  <pre><code>spring.cloud.gateway.routes[0].id=users-status-check
  spring.cloud.gateway.routes[0].uri=lb://users-ws
  spring.cloud.gateway.routes[0].predicates[0]=Path=/users-ws/users/status
  spring.cloud.gateway.routes[0].predicates[1]=Method=GET
  spring.cloud.gateway.routes[0].predicates[2]=Header=Authorization, Bearer (.*)
  spring.cloud.gateway.routes[0].filters[0]=RewritePath=/users-ws/(?&lt;segment&gt;.*), /${segment}
  spring.cloud.gateway.routes[0].filters[1]=AuthorizationHeaderFilter
  </code></pre>
  <p>When try to send request this endpoint it doesnt start the the debugger or print logs to the console. What i'am missing here. Thank you.</p>
  <p>if i create the bean of AuthorizationHeaderFilter in my main application like this</p>
  <pre><code>@SpringBootApplication
  public class ApiGatewayApplication {
  
     public static void main(String[] args) {
         SpringApplication.run(ApiGatewayApplication.class, args);
     }
  
  
     @Bean
     public AuthorizationHeaderFilter authorizationHeaderFilter() {
      return new AuthorizationHeaderFilter();
     }
  }
  </code></pre>
  <p>Application throws this error on startup</p>
  <pre><code>org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'authorizationHeaderFilter' defined in com.springcloud.photoapp.api.ApiGateway.ApiGatewayApplication: @Bean definition illegally overridden by existing bean definition: Root bean: class [org.springframework.aop.scope.ScopedProxyFactoryBean];
  </code></pre>
  <p>I also setted logging level to debug for cloud api gateway, here is the logs</p>
  <pre><code> Mapping [Exchange: GET http://localhost:8764/users-ws/users/status] to 
   Route{id='ReactiveCompositeDiscoveryClient_USERS-WS', uri=lb://USERS-WS, 
   order=0, predicate=Paths: [/users-ws/**], match trailing slash: true, 
   gatewayFilters=[[[RewritePath /users-ws/(?&lt;remaining&gt;.*) = '/${remaining}'], 
   order = 1]], metadata={}}
   
   RouteDefinition users-status-check applying {_genkey_0=/users- 
   ws/users/status} to Path
   RouteDefinition users-status-check applying {_genkey_0=GET} to Method
   RouteDefinition users-status-check applying {_genkey_0=Authorization, 
   _genkey_1=Bearer (.*)} to Header
   RouteDefinition users-status-check applying filter {_genkey_0=/users-ws/(? 
   &lt;segment&gt;.*), _genkey_1=/${segment}} to RewritePath
   RouteDefinition users-status-check applying filter {} to 
   AuthorizationHeaderFilter
  </code></pre>