解決 '@' that cannot start any token. (Do not use @ for indentation)


在一個MavenSpringBoot項目中出現 '@' 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@
              ^

分析:

artifactIdmaven屬性,我們知道使用mavne屬性是使用${}的方式,為什么上面使用@@的方式呢,這是因為為了避免與SpringBoot的變量沖突,在spring-boot-starter-parentmavne-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>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM