知乎專欄 | 多維度架構 | | | 微信號 netkiller-ebook | | | QQ群:128659835 請註明“讀者” |
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
application.properties
跨域配置
management.endpoints.web.cors.allowed-origins=https://example.com management.endpoints.web.cors.allowed-methods=GET,POST
security.basic.enabled=true security.basic.path=/admin #針對/admin路徑進行認證 security.user.name=admin #認證使用的用戶名 security.user.password=password #認證使用的密碼 management.security.roles=SUPERUSER management.port=11111 #actuator暴露介面使用的連接埠,為了和api介面使用的連接埠進行分離 management.context-path=/admin #actuator暴露介面的首碼 management.security.enabled=true #actuator是否需要安全保證 endpoints.metrics.sensitive=false #actuator的metrics介面是否需要安全保證 endpoints.metrics.enabled=true endpoints.health.sensitive=false #actuator的health介面是否需要安全保證 endpoints.health.enabled=true
neo@MacBook-Pro ~ % curl -s http://localhost:8080/actuator | jq { "_links": { "self": { "href": "http://localhost:8080/actuator", "templated": false }, "health": { "href": "http://localhost:8080/actuator/health", "templated": false }, "health-component": { "href": "http://localhost:8080/actuator/health/{component}", "templated": true }, "health-component-instance": { "href": "http://localhost:8080/actuator/health/{component}/{instance}", "templated": true }, "info": { "href": "http://localhost:8080/actuator/info", "templated": false } } }
curl localhost:8080/actuator/health
neo@MacBook-Pro ~ % curl -s http://localhost:8080/actuator/health | jq { "status": "UP" }
配置檔案中加入
management.endpoint.shutdown.enabled=true
curl -X POST localhost:8080/actuator/shutdown
返回 application.properties 檔案中定義的 info 配置信息,如:
# info端點信息配置 info.app.name=spring-boot-example info.app.version=v1.0.0
neo@MacBook-Pro ~ % curl -s http://localhost:8080/actuator/info | jq { "app": { "name": "spring-boot-example", "version": "v1.0.0" } }