Gateway如何使用配置类重写路由转发路径

问题遇到的现象和发生背景

网上查了很多,都是基本使用的配置文件来实现,能否用配置类来实现?

spring:
  application:
    name: gateway
  cloud:
    gateway:
      routes:
        - id: product
          uri: lb://product # lb代表从注册中心获取服务
          predicates:
            - Path=/product-service/**
          filters: 
            - RewritePath=/product-service/(?<segment>.*), /$\{segment}

通过RewritePath配置重写转发的url,将/product-service/(?.*),重写为{segment},然后转发到订单微服务。比如在网页上请求http://localhost:8080/product-service/product/1,此时会将请求转发到http://127.0.0.1:9002/product/1( 值得注意的是在yml文档中 $ 要写成 $\ )
原文链接:https://blog.csdn.net/qq_41347385/article/details/106528642

我想要达到的结果
@Configuration
public class GateWayConfig {
    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder routeLocatorBuilder) {

        RouteLocatorBuilder.Builder routes = routeLocatorBuilder.routes();

        routes.route("routh_1",
                r -> r.path("/product-service/**")
                        .uri("lb://system")).filter(???);  // 此处应该怎么写来重写路径
        return routes.build();
    }

}
@Component
@Order(90)
public class WebFluxFilter implements WebFilter {

    @Override
    public @NotNull Mono<Void> filter(ServerWebExchange exchange, @NotNull WebFilterChain chain) {

       // 此处应该怎么写来重写路径
       // ... ???
       return chain.filter(exchange);
        

    }
}

如何在过滤器中编写,可以使得最终转发的路由也改变,
比如默认gateway请求localhost:9090/hello转发到localhost:7070/hello
现在如何设置好后,
可以使得localhost:9090/hello转发到localhost:7070/very/good