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

时间:2016-07-08 07:02:48

标签: spring spring-boot spring-boot-actuator

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

/env ->     /secure/env
/health ->  /secure/health
/info ->    /secure/info
...

3 个答案:

答案 0 :(得分:24)

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

management:
  context-path: /secure

-> /secure/env
-> /secure/health
...

答案 1 :(得分:11)

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

要在端点上启用安全性,请将endpoints.{name}.sensitive设置为true。例如:

endpoints.health.sensitive=true

如果要保护应用程序的执行器端点,请参阅Spring Boot参考文档中的Securing sensitive endpointsActuator SecurityHTTP health endpoint access restrictions

有关可在application.properties中设置的常用属性的列表,请参阅Spring Boot参考文档中的Common application properties

答案 2 :(得分:7)

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

management.endpoints.web.base-path=/secure