为所有Spring Boot执行器端点添加前缀

cod*_*ent 19 spring spring-boot spring-boot-actuator

是否有一种简单的方法可以为所有Actuator端点添加前缀?

/env ->     /secure/env
/health ->  /secure/health
/info ->    /secure/info
...
Run Code Online (Sandbox Code Playgroud)

cod*_*ent 26

Jesper的答案是完全正确的,但我一直在寻找一种更简单的方法来为所有端点添加前缀,并且可以使用management.context-path,例如:

management:
  context-path: /secure

-> /secure/env
-> /secure/health
...
Run Code Online (Sandbox Code Playgroud)

  • 在Spring Boot 2中更改为`management.endpoints.web.base-path`https://docs.spring.io/spring-boot/docs/2.1.x/reference/htmlsingle/#production-ready-customizing-management-服务器上下文路径 (5认同)

Jes*_*per 12

设置endpoints.{name}.path您的属性application.properties.例如:

endpoints.actuator.path=/secure/actuator
endpoints.env.path=/secure/env
endpoints.health.path=/secure/health
endpoints.info.path=/secure/info
Run Code Online (Sandbox Code Playgroud)

要在端点上启用安全性,请设置endpoints.{name}.sensitivetrue.例如:

endpoints.health.sensitive=true
Run Code Online (Sandbox Code Playgroud)

另请参见保护敏感终点,执行器安全性HTTP健康端点准入限制春季启动参考文档中,如果你想以确保您的应用程序的执行端点.

有关可以设置的常用属性的列表,请参阅Spring Boot参考文档中的常见应用程序属性application.properties.


Dar*_*est 9

根据当前的Spring-Boot文档,要更改的属性是:

management.endpoints.web.base-path=/secure
Run Code Online (Sandbox Code Playgroud)