spring-boot-actuator - spring cloud gateway,你能排除路径吗(做一个全局的!=)

标签 spring-boot-actuator spring-cloud-gateway

我希望有人能在这里提供一些想法。我正在使用 spring cloud gateway 的一些示例应用程序并浏览文档,但我没有看到任何路由到自身或进行全局忽略的方法。这里的想法是,有些路径总是需要指向自己,比如执行器,而其他路径可能需要一个全局 block (可能出于安全原因,比如你发现了一个严重的漏洞,需要禁用对特定资源)。目前据我所知,没有办法做到这一点,但我希望我是错的!

我已将应用设置为执行器在端口 8081 上运行,服务器在 8080 上运行。 我有两个简单的规则:

  - id: local_test_1
    uri: http://localhost:80
    order: 9000
    predicates:
    - Path=/echo
  # =====================================
  - id: local_test_2
    uri: ${test.uri}
    order: 10000
    predicates:
    - Path=/**

但是通用/** 确保对 localhost:8081/actuator/* 的任何调用也被路由到 uri。如何从路由规则中免除管理端口,以便服务器自己处理请求?

我认为像 Path!=${management.server.port}/* 这样的默认过滤器可能有效,但似乎不支持 !=。

最佳答案

我在使用默认路由时遇到了同样的问题,但还需要从类路径提供自定义的注销后页面。默认路由将处理请求而不是网关本身。在没有默认路由的情况下,logout.html 得到了正确的服务。

我最终将默认路由移动到 Java bean 并像这样使用流畅的 API:

@Bean
public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
    return builder.routes()
            .route("default", r -> r
                .order(Ordered.LOWEST_PRECEDENCE)
                .path("/**")
                .and().not(p -> p.path("/logout.html", "/logout.css"))
                .uri("http://localhost:8080")
            )
            .build();
}

如果有人知道在 .yml 配置文件中进行否定的方法那将是理想的,但我还没有在任何文档中找到这样的示例。

关于spring-boot-actuator - spring cloud gateway,你能排除路径吗(做一个全局的!=),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52841711/

相关文章:

spring-cloud-gateway - 如何在 Spring Cloud Gateway 中将 HTTP 重定向到 HTTPS

spring - Spring Cloud Gateway全局异常处理/记录

java - Spring boot 1.x,如何将指标增加一定量

spring - 选择组件加载顺序

json - Spring Boot Actuator pretty-print JSON

java - 启用具有 JWT 安全性的 Spring Boot 2.0 Actuator 端点

spring-boot-actuator - management.server.port 和 management.port 属性有什么区别?

spring-boot - Spring Cloud 网关在过滤器中发送响应

spring-boot - 使用 Spring Security 保护 Spring Cloud Gateway

netflix-zuul - Spring Cloud Gateway 与 Zuul-2 有何不同