SpringBoot 多环境设置@profileActive@ | 最新快讯

多环境设置

有以下几种环境
application.yml
application-dev.yml 开发环境
application-pro.yml 生产环境
application-test.yml 测试环境

配置application.yml环境
spring:
  profiles:
    #多环境配置
    active: @profileActive@

@profileActive@是可配置多环境设置
需要配置POM配置,不然启动会报错:

Caused by: org.yaml.snakeyaml.scanner.ScannerException: while scanning for the next token
found character '@' that cannot start any token. (Do not use @ for indentation)
 in 'reader', line 19, column 13:
        active: @profileActive@

POM新增配置如下:

    <!--多环境配置优先级,默认配置dev -->
    <profiles>
        <profile>
            <id>dev</id>
            <properties>
                <profileActive>dev</profileActive>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <id>test</id>
            <properties>
                <profileActive>test</profileActive>
            </properties>
        </profile>
        <profile>
            <id>pro</id>
            <properties>
                <profileActive>pro</profileActive>
            </properties>
        </profile>
    </profiles>

配置了以上设置会maven会出现可选择打包环境选项,可选择对应的启动环境

对@profileActive@标识符的解析插件

          <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <delimiters>
                        <delimiter>@</delimiter>
                    </delimiters>
                    <useDefaultDelimiters>false</useDefaultDelimiters>
                </configuration>
            </plugin>

resource的配置

            <resource>
                <!-- 指定文件路径 -->
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <!-- **表示任意级目录,*表示任意文件 -->
                    <include>**/*</include>
                </includes>
            </resource>

最后刷新mvn
 


如果不行clean再更新一次

  • 10
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

www3300300

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值