1. 程式人生 > >spring boot應用啟動及關閉方式

spring boot應用啟動及關閉方式

一、spring boot啟動方式

1、在IDE中啟動spring boot應用專案的啟動 類Appplication.java的main方法;

比如:@SpringBootApplicationpublic class EurekaClientApplication { public static void main(String[] args) { new SpringApplicationBuilder(EurekaClientApplication.class).web(true).run(args); }}

2、在spring boot應用的根目錄下使用maven命令執行(maven專案):mvn spring-boot:run

3、使用啟動jar的方式,步驟如下:

A、進入spring boot應用根目錄;

B、輸入命令:mvn install -Dmaven.test.skip=true

C、cd target

D、java -jar ****.jar

二、spring boot應用關閉操作(Linux/unix/ubuntu環境下進行)

A、非安全驗證 1、專案pom.xml新增如下依賴包: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> 2、application.properties檔案新增如下內容: #啟用shutdownendpoints.shutdown.enabled=true#禁用密碼驗證endpoints.shutdown.sensitive=false 3、關閉命令: curl -X POST host:port/shutdown B、安全驗證 1、pom.xml新增如下依賴包: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> 2、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 3、關閉命令: curl -u admin:admin -X POST http://127.0.0.1:8081/manage/shutdown