首页 > 其他 > 详细

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

时间:2021-07-07 10:23:07      阅读:38      评论:0      收藏:0      [点我收藏+]

在一个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>

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

原文:https://www.cnblogs.com/zuojl/p/14977544.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!