org.yaml.snakeyaml.scanner.ScannerException: while scanning for the next token

爱被打了一巴掌 2023-10-08 19:36 124阅读 0赞

pom.xm 中定义多环境配置如下:

  1. <!-- maven多环境打包配置 -->
  2. <profiles>
  3. <profile>
  4. <!-- 开发 -->
  5. <id>dev</id>
  6. <activation>
  7. <activeByDefault>true</activeByDefault>
  8. </activation>
  9. <properties>
  10. <activatedProperties>dev</activatedProperties>
  11. </properties>
  12. </profile>
  13. <profile>
  14. <!-- 测试 -->
  15. <id>test</id>
  16. <properties>
  17. <activatedProperties>test</activatedProperties>
  18. </properties>
  19. </profile>
  20. <profile>
  21. <!-- 生产 -->
  22. <id>prod</id>
  23. <properties>
  24. <activatedProperties>prod</activatedProperties>
  25. </properties>
  26. </profile>
  27. </profiles>

application.yml中使用@引入

  1. spring:
  2. profiles:
  3. #对应pom中的配置
  4. active: @activatedProperties@

无法识别 @ 符号
在这里插入图片描述

  1. 10:23:26.711 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
  2. org.yaml.snakeyaml.scanner.ScannerException: while scanning for the next token
  3. found character '@' that cannot start any token. (Do not use @ for indentation)
  4. in 'reader', line 6, column 13:
  5. active: @activatedProperties@

在这里插入图片描述
然后在 idea 中点击maven 重新加载一下项目
在这里插入图片描述
如果不行,检查一下项目,在模块的pom.xml文件下引入一下配置

  1. <build>
  2. <!--如果不设置resource 会导致application.yml中的@@找不到pom文件中的配置-->
  3. <resources>
  4. <resource>
  5. <directory>src/main/resources</directory>
  6. <filtering>true</filtering>
  7. </resource>
  8. </resources>
  9. </build>

发表评论

表情:
评论列表 (有 0 条评论,124人围观)

还没有评论,来说两句吧...

相关阅读