java – Spring Profile包含yaml文件的问题

前端之家收集整理的这篇文章主要介绍了java – Spring Profile包含yaml文件的问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_403_1@当团队设置websphere配置文件激活时,我正在尝试完成云配置文件也已激活.

@H_403_1@yaml文件

@H_403_1@

   ---
    spring:
      application:
        name: kicapp
      output:
        ansi:
          enabled: ALWAYS
      profiles:
        active: local
    #server:
      #context-path: /
      #port: 8080
    #logging:
      #level:
        #org.springframework.security: DEBUG
    ---
    spring:
      profiles: local
    ---
    spring:
      profiles: unittest
    ---
    spring:
      profiles: cloud
      test: loaded
    ---
    spring:
      profiles: websphere
        include: cloud
@H_403_1@当我设置–spring.profiles.active = websphere时,我收到以下错误

@H_403_1@

@H_403_1@Caused by: mapping values are not allowed here in ‘reader’,line 28,
column 12:
include: cloud

最佳答案
这似乎是对SnakeYAML解析器的限制以及Spring Boot使用它的方式.由于yaml允许在带有—分隔符的单个文件中指定多个不同的文档,因此Spring分离出单独文档的方式是使用spring.profiles键,这个键应该是一个简单的结构而不是一个复杂的结构.

@H_403_1@一个好的解决方法实际上是通过这种方式将其拆分为多个文件

@H_403_1@具有共同内容的application.yaml,
应用程序 – <型材>使用特定于配置文件的扩展,使用此结构键spring.profiles.include将按预期工作.

猜你在找的Spring相关文章