简体   繁体   English

如何在不删除 Actuator 的情况下在 Spring Boot 中开发我自己的 /env 端点?

[英]How can I develop my own /env endpoint in Spring Boot without remove Actuator?

I have a Spring Boot application (Java 8, Spring Boot 1.5.9) with Actuator, but I need to write my own response for the /env endpoint.我有一个带有 Actuator 的 Spring Boot 应用程序(Java 8,Spring Boot 1.5.9),但我需要为/env端点编写自己的响应。 I tried disabling it with the property endpoints.env.enabled=false but the response that I get is an HTTP 500 instead of an HTTP 404 .我尝试使用属性endpoints.env.enabled=false禁用它,但我得到的响应是HTTP 500而不是HTTP 404

Is there any way to write my own /env endpoint without remove all the Actuator library of the project?有没有办法在不删除项目的所有 Actuator 库的情况下编写我自己的/env端点?

Thanks in advance.提前致谢。

I manage to do this in two steps:我设法分两步做到这一点:

First, re-map the /env path to something else in the application.properties file, eg:首先,将/env路径重新映射到application.properties文件中的其他内容,例如:

management.endpoints.web.path-mapping.env=default-env

Second, write our own endpoint implementation for the /env endpoint, eg其次,为/env端点编写我们自己的端点实现,例如

@RestController
public class EnvController {
    @GetMapping(value="/actuator/env")
    public ResponseEntity<String> env() {
        return ResponseEntity.ok("My custom env endpoint");
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM