设置系统属性(system property)
通过配置systemPropertyVariables
来设置系统属性(system property)。以下示例将 property1
设置为 test
,将 property2
设置为 42,将property3
设置为空字符串。
<build>
<properties>
<my.value>42</my.value>
</properties>
...
<plugins>
...
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<!-- property1='test' -->
<property1>test</property1>
<!-- property2=42 -->
<property2>${my.value}</property2>
<!-- property3='' -->
<property3/>
<!-- property4='' -->
<property4></property4>
</systemPropertyVariables>
</configuration>
...
</plugin>
...
</plugins>
...
</build>
-
如果属性值为空,或未指定,如上例中的
<property4></property4>
和<property3/>
,系统将把空字符串赋值给属性 -
赋值时,maven将剪裁掉值两端的空格。因此不能赋以空格开头或结尾的值。如需要这样的值,可以考虑用jvm参数代替,
systemPropertyVariables
通过设置jvmArguments
来设置jvm参数,具体方法请参考spring-boot-maven-plugin:debug调试程序 -
可用字符串类型的maven变量给系统属性赋值,例如
<property2>${my.value}</property2>
。其他类型的maven变量,如List、URL,不会被计算,只会按字面量赋值。 -
jvmArguments
参数的优先级比系统属性高,如下示例中,在下面的示例中,property1
的值将被覆盖为“overridden”
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Dproperty1=overridden"
设置环境变量(environment variables)
通过配置environmentVariables
来设置环境变量(environment variables)。以下示例将ENV1
设置为 5000
,将 ENV2
设置为Some Text
,将ENV3
、ENV4
设置为空字符串。
<build>
...
<plugins>
...
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<environmentVariables>
<!-- ENV1=5000 -->
<ENV1>5000</ENV1>
<!-- ENV2='Some Text' -->
<ENV2>Some Text</ENV2>
<!-- ENV3='' -->
<ENV3/>
<!-- ENV4='' -->
<ENV4></ENV4>
</environmentVariables>
</configuration>
...
</plugin>
...
</plugins>
...
</build>
- 如果变量值为空,或未指定,如上例中的
<ENV4></ENV4>
和<ENV3/>
,系统将把空字符串赋值给变量 - 赋值时,maven将剪裁掉值两端的空格。因此不能赋以空格开头或结尾的值
- 可用字符串类型的maven变量给系统属性赋值。其他类型的maven变量,如List、URL,不会被计算,只会按字面量赋值
- 以这种方式设置的环境变量会覆盖已有值