当团队设置websphere配置文件激活时,我正在尝试完成云配置文件也已激活。
yaml文件
---
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
当我设置--spring.profiles.active=websphere
时,我收到以下错误
引起:'读者',第28行,第12栏中不允许使用映射值:include:cloud
这似乎是对SnakeYAML
解析器的限制以及Spring Boot使用它的方式。由于yaml允许使用---
分隔符在单个文件中指定多个不同的文档,因此Spring分离出单独文档的方式是使用spring.profiles
键,这个键很可能是一个简单的结构而不是复杂的结构。
一个好的解决方法实际上是通过这种方式将其拆分为多个文件:
application.yaml
具有共同内容,application-<profile>
具有特定于配置文件的扩展,具有此结构的关键spring.profiles.include
将按预期工作。
根据Biju的回答,如果您想使用---
分隔符保留单个文件而不使用单独的配置文件,则可以按如下方式定义spring.profiles.include
密钥:
---
spring:
profiles: currentProfile
profiles.include: profileToInclude
这样,解析并不存在复杂的结构。