Issue
This Content is from Stack Overflow. Question asked by Katlock
I am currently following an example to forward jwt tokens from a spring gateway service to a backend microservice.
The api-gateway example uses org.springframework.cloud.security.oauth2.gateway.TokenRelayGatewayFilterFactory
to relay token to backend microservice but it is now deprecated.
It comes from this depenendency:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-security</artifactId>
</dependency>
The following is the existing code that uses the deprecated api:
public RouteLocator customRouteLocator(RouteLocatorBuilder builder, TokenRelayGatewayFilterFactory filterFactory) {
return builder.routes()
.route("car-service", r -> r.path("/cars")
.filters(f -> f.filter(filterFactory.apply()))
.uri("lb://car-service"))
.build();
What is the new api to use?
Solution
I couldn’t delete it so I will answer my own question.
I changed my spring boot version to following:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
and I was already referencing this dependency also:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
and referenced this import:
org.springframework.cloud.gateway.filter.factory.TokenRelayGatewayFilterFactory;
This Question was asked in StackOverflow by Katlock and Answered by Katlock It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.