yml使用@project.artifactId@启动异常

发布时间 2023-07-04 08:49:36作者: 百里浅暮
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 5, column 12:
      appName: @project.artifactId@
               ^

在pom.xml中添加

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <configuration>
                <delimiters>@</delimiters>
                <useDefaultDelimiters>false</useDefaultDelimiters>
            </configuration>
        </plugin>
    </plugins>
    <!--必须添加,否则无法动态获取值-->
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

application.yml的配置,要加双引号或单引号

info:
  appName: "@project.artifactId@"
  version: "@project.version@"
  company: 测试项目
  author: linhongwei