springboot报ScannerException:character ‘@‘ that cannot start any token. (Do not use @ for indentation
springboot @@,报ScannerException
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 28, column 20:
          defaultZone: @eurekaDefaultZone@ 在解决问题之前,我们先来看看为什么会出现这个问题? 
springboot项目使用@@占位符引用maven项目属性
我们知道,在springboot项目中,可以使用Maven的资源过滤(resource filter)自动暴露来自Maven项目的属性,如果使用parent
spring-boot-starter-parent 作为项目的父工程的话,我们可以通过@..@占位符引用Maven项目的属性。
    
        org.springframework.boot 
        spring-boot-starter-parent 
        2.1.4.RELEASE 
          
      你在maven配置文件 pom.xml中设置启动文件:
        
            local 
            
                true 
             
            
                local 
                local 
             
         
        
            production 
            
                production 
                production DefaultZone>
          
     你就可以在application.yml文件里读取到上面profileActive的值:
spring:
  profiles:
    active: @profileActive@ 这是为什么呢?这是因为, spring-boot-starter-parent自带自动化的资源过滤,那什么是资源过滤呢?
上面我们为本地环境和开发环境配置了不同的profile,在我们的代码里,就可以使用@xxx@来引用到属性,例如上面例子中,我们默认开启的环境是 带有 activeByDefault = true 的local环境,所以@profileActive@读到的是  profile id = local 的文件下,profileActive的值,即local。
ScannerException
但是如果你的springboot项目如果没有指定spring-boot-starter-parent的话,使用@@的时候就会报ScannerException异常:
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 28, column 20:
          defaultZone: @eurekaDefaultZone@
                       ^ 这时候,你需要在你pom文件的build节点加上如下的配置:
         
        
            
                src/main/resources 
                
                true 
             
         
      启动项目,一切正常,这是因为我们这里手动配置了资源过滤。
来源:https://blog.csdn.net/weixin_40910372/article/details/108199525
- 本文标签: Spring Boot
 - 版权声明: 本文为互联网转载文章,出处已在文章中说明(部分除外)。如果侵权,请联系本站长删除,谢谢。