Run parameter settings VM options and Program arguments

The parameters that can be added to Configuration are mainly the following three categories:

Added parameter priority

Program arguments > VM options > Environment variable > 系统默认值

 1、Program arguments

Program arguments is the string array args[] passed into the main method

// Program arguments有两种类型,一种是以--key=value的形式;一种是直接写value
// 参数之间空格分隔
--mode=debug test

Add method

access method

2、VM options

VM options are actually the runtime environment variables we need in the program. They need to start with -D or -X or -XX, and each parameter is separated by a space.

The most commonly used method is -Dkey=value to set system property values, such as -Dspring.profiles.active=dev

Add method

// -D开头 + 参数名 = 参数值
// = 两侧没有空格
// 不同参数之间空格分隔
// 如下所示我们增加两个参数 Env 和 Name
-DEnv=prod -DName=admin

access method

// System.getProperty("参数名")
System.getProperty("Env");
System.getProperty("Name");

3、Environment variables

Environment variables have no prefix

Add method

// 参数名=参数值
// 多个参数之间使用分号分隔(注意这里不是用空格分隔)
password=123456;name=admin

access method

// System.getenv("参数名")
System.getenv("password");
System.getenv("name");

Parameter Description:

1. VM options

VM options are actually the runtime environment variables we need in the program. They need to start with -D or -X or -XX, and each parameter is separated by a space.

The most commonly used method is -Dkey=value to set system property values, such as -Dspring.profiles.active=dev3

二、Program arguments

Program arguments is the string array args[] we passed into the main method, which usually starts with --, such as --spring.profiles.active=dev3

Equivalent to -Dspring.profiles.active=dev3. If both exist, the Program arguments configuration takes precedence.

三、Environment variables

Environment variables have no prefix and have lower priority than VM options. That is, if VM options has a variable with the same key as the variable in Environment variable, the VM options will prevail.

 

Guess you like

Origin blog.csdn.net/qq_16504067/article/details/129985489