打包命令
mvn clean package -Dmaven.test.skip=true
或在eclipse中运行run -> Maven build...
,在Goals中填写clean package -Dmaven.test.skip=true
,运行,打包完成。
Spring Boot应用关闭的前提条件是POM.xml
添加以下内容:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
application.properties
中添加:
#启用shutdown endpoints.shutdown.enabled=true #禁用密码验证 endpoints.shutdown.sensitive=false
关闭命令为:
curl -X POST host:port/shutdown # Demo $ curl -X POST http://localhost:8080/shutdown {"message":"Shutting down, bye..."} $ curl -X POST http://localhost:8080/manage/shutdown {"message":"Shutting down, bye..."}
如果要配置路径,需要在application.properties
中添加management.context-path=/manage
,则关闭命令变为curl -X POST host:port/manage/shutdown
。
安全验证
如果在关闭时需要安全验证,则在pom.xml
文件中添加:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency>
application.properties
中添加:
#开启shutdown的安全验证 endpoints.shutdown.sensitive=true #验证用户名 security.user.name=admin #验证密码 security.user.password=admin #角色 management.security.role=SUPERUSER # 指定端口 management.port=8081 # 指定地址 management.address=127.0.0.1关闭命令为:
curl -u admin:admin -X POST http://127.0.0.1:8081/manage/shutdown # Demo $ curl -u admin:admin -X POST http://127.0.0.1:8081/manage/shutdown {"message":"Shutting down, bye..."}
获取SpringBoot微服务进程PID
jps|grep 服务名称|awk '{print $1}'
扫描二维码关注公众号,回复:
1740367 查看本文章