Spring-boot Adds parameters for boot

1. Add parameters to IDEA

Add either of the following parameters

-Dspring.profiles.active=test -Dserver.port=8081
#orspring.profiles.active=test; server.port=8081Copy the code

2. Add parameters during startup

Corresponding to the above parameters in the start JAR package is to add parameters

  • The first kind of

    java -jar -Dspring.profiles.active=test -Dserver.port=8081 app.jar
    Copy the code
  • The second,

    java -jar app.jar --spring.profiles.active=test --server.port=8081
    Copy the code
  • Third, mix it up

    java -jar -Dspring.profiles.active=test app.jar --server.port=8081
    Copy the code

3. Server

Writing shell scripts

APP_NAME=app.jar usage() { echo "Usage: Sh script execution. Sh [start | stop | restart | status] "exit 1} is_exist () {pid = $(ps - ef | grep $APP_NAME | grep -v grep | awk '{print  $2}') if [ -z "$pid" ]; then return 1 else return 0 fi } start() { is_exist if [ $? -eq "0" ]; then echo "$APP_NAME is already running. pid=$pid ." else nohup java -jar $APP_NAME >/dev/null 2>&1 & fi } stop() { is_exist if [ $? -eq "0" ]; then kill -9 $pid else echo "$APP_NAME is not running" fi } status() { is_exist if [ $? -eq "0" ]; then echo "$APP_NAME is running. Pid is $pid" else echo "$APP_NAME is NOT running." fi } restart() { stop start } case "$1" in "start") start ;; "stop") stop ;; "status") status ;; "restart") restart ;; *) usage ;; esacCopy the code

Upload the app.jar and app.sh scripts to the same directory

The startup script

#Sh app. Sh [start | stop | restart | status] for start, stop, restart, view state
sh app.sh start
Copy the code

Thank you for browsing, like a thumbs-up 👍, welcome to leave a message, discuss together!