SpringBoot 多环境设置 active: @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再更新一次

浙公网安备 33010602011771号