[英]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.