spring-boot-maven-plugin:添加系统属性和环境变量

设置系统属性(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,将ENV3ENV4设置为空字符串。

<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,不会被计算,只会按字面量赋值
  • 以这种方式设置的环境变量会覆盖已有值
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值