-
在可能需要被终止的微服务的pom.xml中引入spring-boot-actuator的依赖
org.springframework.boot spring-boot-starter-actuator -
在application.yml或者application.properties中配置actuator的相关属性
#基础路径 management.endpoints.web.base-path=/actuator #手动开启服务终止功能 management.endpoint.shutdown.enabled=true #可暴露的服务 management.endpoints.web.exposure.include=*
-
终止微服务的核心逻辑,通过post方式发起http请求
如果微服务有加密的话,需要给post请求设置cookie,发起请求后,该地址的微服务会自动停止运行
HttpPost、HttpClient等需要引入对应依赖#服务ip,可自定义获取,此处举例写死 String address = "http://localhost:8080"; String url = address + "/actuator/shutdown"; HttpPost httpPost = new HttpPost(url); HttpClient.createDeafulrtClient().execute(httpPost);



