Spring Boot yml 文件中无法通过 @@ 使用 pom 文件中定义的变量
错误信息如下
java.lang.IllegalStateException: Failed to load property source from location 'classpath:/application.yml'
... ...
Caused by: while scanning for the next token
found character '@' that cannot start any token. (Do not use @ for indentation)
in 'reader', line 3, column 11:
name: @project.artifactId@
^
解决方法:在 pom 文件中配置 <filtering>true</filtering>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
关于 filtering 元素
Whether resources are filtered to replace tokens with parameterised values or not. The values are taken from the properties element and from the properties in the files listed in the filters element. Note: While the type of this field is String for technical reasons, the semantic type is actually Boolean. Default value is false.