天天看点

[Spring Boot]通过命令启动&关闭

1.首先通过intellij的maven管理器Lifecycle-->package打包

2.在项目目录-->target找到项目jar包.

3.命令示例:

java -jar demo-0.0.1-SNAPSHOT.jar --spring.profile.active=peer1      

 *注意,如果使用java9以上会报错,详细请见另一篇博文.

4.如何关闭:

MAC下查找端口: lsof -n -P -i TCP -s TCP:LISTEN

kill -9 pid

还有一种更优雅的关闭:

先在yaml下添加:

management:
  endpoints:
    web:
      exposure:
        include: '*'
  endpoint:
    shutdown:
      enabled: true      
curl -XPOST http://localhost:1111/demo/actuator/shutdown      

 2.https://stackoverflow.com/questions/48900892/how-to-enable-all-endpoints-in-actuator-spring-boot-2-0-0-rc1

3.https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Migration-Guide#endpoints

补充:

Spring Boot 2.0有很多改动,例如endpoins的接口不是全部开放,只开放了/actuator,/health,如果需要开放其他,需要添加:

properties:

management.endpoints.web.exposure.include=*      

 yaml:(注意'*'必须要单引号)

management:
  endpoints:
    web:
      exposure:
        include: '*'      

 或者有选择地添加:

management:
  endpoints:
    web:
      exposure:
        include: info, health, metrics      

 同时endpoint下的url,全部在/actuator下,例如/shutdown都要变成/actuator/shutdown才能成功.(网上很多shutdown的资料都是基于spring boot 1.0的,这个命令困扰我太久了

[Spring Boot]通过命令启动&关闭

)