Spring Cloud Gateway error: 'tokenRelayGatewayFilterFactory' could not be registered

971 Views Asked by At

I'm learning from a Youtube tutorial (https://youtu.be/9b6OOGMpx5Y) to implement a microservices system having about 5 microservices with an API Gateway. The API Gateway is using the Spring Cloud Gateway library which I named "api-gateway-service". I'm new to Spring Cloud Gateway and I'm trying to figure out what it's saying here in the error log on application boot up as it seems to be having a problem with Token Relay but I don't know what exactly it is and where is it that it is causing this problem from:

Error Log

I could set the property spring.main.allow-bean-definition-overriding=true in application.properties file so it would be able to boot up the application but Token Relay-ing wouldn't work.

Has anyone approached this error before and do you know a solution to fix it? Thanks!

1

There are 1 best solutions below

0
On

TokenRelayGatewayFilterFactory is removed from the spring cloud security and moved to the Spring cloud gateway.

I have recently encoutered this issues. Here, see the documentation spring doc

But first of all make sure you have this dependency in your pom.xml file.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>

Instead of Autowiring the TokenRelayGatewayFilterFactory, you can do like this

@Configuration
@RefreshScope
public class RouteConfiguration {

  @Bean
  public RouteLocator apiRoutes(
      RouteLocatorBuilder builder) {
    return builder
        .routes()
        .route(
            "CHOICE A ROUTE ID",
            p ->
                p.path("/api/**")
                    .filters(f -> f.tokenRelay())
                    .uri("http://localhost:8080"))
        .build();
  }
}