@profiles.active@多环境配置以及遇到Do not use @ for indentation

发布时间 2023-08-30 11:30:40作者: 鸭猪是的念来过倒

1:配置环境

maven pom.xml增加

<!--环境-->
    <profiles>
        <profile>
            <id>dev</id>
            <properties>
                <profiles.active>dev</profiles.active>
            </properties>
        </profile>
        <profile>
            <id>test</id>
            <properties>
                <profiles.active>test</profiles.active>
            </properties>
        </profile>
    </profiles>
<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <configuration>
                    <delimiters>
                        <delimiter>@</delimiter>
                    </delimiters>
                    <useDefaultDelimiters>false</useDefaultDelimiters>
                </configuration>
            </plugin>

2:修改配置文件写法

spring:
  profiles:
    active: @profiles.active@

3:问题

如果出现如下错误

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 3, column 13:
        active: @profiles.active@
                ^

不一定是写法错了!!!

先mavne clean一下,把boot项目也清理掉,如果target文件还在,可以手动直接删掉它。然后选中项目,Reload Project。

启动,如果还有问题,在考虑是否是写法问题!