###### tags: `SpringBoot` `Monitor` # Spring Boot Application Programmatically Monitoring and Restating ## 使用對象 > 當專案使用Spring boot project建置時可以使用,例如Spring rest service ## 安裝方式 1. Adding the Actuator Dependency ```maven= <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter</artifactId> </dependency> ``` 2. Setting the application.properties ```properties= #Spring Boot Restart Endpoint management.endpoint.restart.enabled=true management.endpoints.web.exposure.include=restart,health #=====(Option)===== server.servlet.contextPath=/definedContextPath # Show details of health endpoint management.endpoint.health.show-details=always ``` ## 測試 ### Monitor status > curl GET http://localhost:{PORT}{CONTEXTPATH}/actuator/health  ### Restart service > curl -X POST http://localhost:{PORT}{CONTEXTPATH}/actuator/restart   ## 參考資源 * [Spring Boot Actuator: Production-ready Features](https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html#actuator.enabling) * [How to Restart Spring Boot Automatically using Actuator](https://javapointers.com/spring/spring-boot/how-to-restart-spring-boot-automatically-using-actuator/)
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up