【问题标题】:Call actuator within controller Spring Boot在控制器 Spring Boot 中调用执行器
【发布时间】:2021-05-02 04:42:16
【问题描述】:

我正在尝试公开一个内部调用弹簧执行器的自定义端点。但我正在阅读超时;嵌套异常是 java.net.SocketTimeoutException: Read timed out。

    @GetMapping(value = "/${spring.application.name}/actuator/health")
    public ResponseEntity<Object> createUser() {
        ResponseEntity<Map> entity = this.restTemplate.getForEntity("http://localhost:" + this.port
                + "/actuator/health", Map.class);

        return new ResponseEntity<>(entity, HttpStatus.OK);
    }


有什么办法让它工作。

【问题讨论】:

  • 你能从邮递员那里调用执行器端点吗?如果是,端点正在工作,我看不出为什么你不能从你的应用程序中调用它。检查您正在调用的 url/端口。无论如何,如果您需要访问健康信息,您可以在不调用端点的情况下访问它们,您可以注入 HealthEndpoint (docs.spring.io/spring-boot/docs/current/api/org/springframework/…) 并访问它们。
  • 是的,我可以从邮递员那里打电话。
  • 如果您不提供更多信息,就很难为您提供帮助。
  • 是的,我可以从邮递员那里调用执行器端点。尽管如此,我无法从控制器调用它。 url 和端口都很好。我读到超时;嵌套异常是 java.net.SocketTimeoutException: Read timed out
  • 执行器端口可能与应用程序端口不同。你从哪里得到端口?

标签: spring-boot spring-boot-actuator


【解决方案1】:

无需创建自己的端点,只需在application.properties 中设置management.endpoints.web.base-path=${spring.application.name}。见https://docs.spring.io/spring-boot/docs/2.1.13.RELEASE/reference/html/production-ready-monitoring.html

【讨论】:

  • 谢谢,你节省了我很多时间
猜你喜欢
  • 2018-09-04
  • 2019-02-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-07
  • 2017-03-22
  • 2018-06-08
  • 2018-11-24
  • 1970-01-01
相关资源
最近更新 更多