解決 '@' that cannot start any token. (Do not use @ for indentation)
阿新 • • 發佈:2021-07-07
在一個Maven
的SpringBoot
專案中出現 '@' that cannot start any token. (Do not use @ for indentation)
異常情況。
在配置檔案 application.yml
中有如下程式碼:
spring:
application:
name: @artifactId@
執行報如下的錯誤:
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 11: name: @artifactId@ ^
分析:
artifactId
是maven
屬性,我們知道使用mavne
屬性是使用${}
的方式,為什麼上面使用@@
的方式呢,這是因為為了避免與SpringBoot
的變數衝突,在spring-boot-starter-parent
中mavne-resources-plugin
外掛中maven
的變數被重新定義了,程式碼如下:
<artifactId>spring-boot-starter-parent</artifactId> <properties> <resource.delimiter>@</resource.delimiter> </properties> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <configuration> <delimiters> <delimiter>${resource.delimiter}</delimiter> </delimiters> <useDefaultDelimiters>false</useDefaultDelimiters> </configuration> </plugin>
到這裡我們知道maven-resources-plugin
外掛沒有替換掉application.yml
中的maven
變數。
解決方案,讓外掛替換配置中的變數:
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>