0
点赞
收藏
分享

微信扫一扫

【异常解决】org.yaml.snakeyaml.scanner.ScannerException: while scanning for the next token found character



SpringBoot获取项目版本号出现的异常问题的处理解决方案

  • 一、背景描述
  • 二、代码实现
  • 三、异常描述
  • 四、解决方案


一、背景描述

技术架构:Spring boot 项目;
项目需求:在浏览器上显示系统项目的版本号;
项目结构:如下图所示:

【异常解决】org.yaml.snakeyaml.scanner.ScannerException: while scanning for the next token found character_xml

在Springboot项目中,可以使用 Maven 的资源过滤(resource filter)自动暴露来自 Maven 项目的属性,如果使用spring-boot-starter-parent 作为项目的父工程的话,我们可以通过@…@占位符引用Maven项目的属性。

二、代码实现

在application.yml 中添加 服务端版本号获取方式:

# 服务端版本号
system:
	server:
		version: @project.version@

【注意:是@@,不是${}】

在代码中使用 @Value注解获取它的值(从 maven 的 pom.xml 配置中获取),然后在接口中返回给前端即可。

三、异常描述

org.yaml.snakeyaml.scanner.ScannerException: while scanning for the next token
found character ‘@’ that cannot start any token. (Do not use @ for indentation

报错详细信息如下:

【异常解决】org.yaml.snakeyaml.scanner.ScannerException: while scanning for the next token found character_解决方案_02

四、解决方案

在 Maven pom.xml 中添加如下信息即可。

<build>     
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <!--开启过滤,用来指定的参数替换directory下的文件中的参数-->
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>

本文完结!


举报

相关推荐

0 条评论