解决 '@' that cannot start any token. (Do not use @ for indentation)
本文章向大家介绍解决 '@' that cannot start any token. (Do not use @ for indentation),主要包括解决 '@' that cannot start any token. (Do not use @ for indentation)使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
在一个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>
原文地址:https://www.cnblogs.com/zuojl/p/14977544.html
参考地址:https://blog.csdn.net/mawei7510/article/details/126658636

浙公网安备 33010602011771号