ndrone
ndrone

Reputation: 3582

Spring Profile include issue with yaml file

I'm trying to accomplish when the team sets the websphere profile active that the cloud profile is also activated.

yaml file

   ---
    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

When I set --spring.profiles.active=websphere I receive the following error

Caused by: mapping values are not allowed here in 'reader', line 28, column 12: include: cloud

Upvotes: 9

Views: 6336

Answers (2)

Tom
Tom

Reputation: 51

Following Biju's answer, if you want to keep the single file with --- separator and not use separate profile files, you can define the spring.profiles.include key as follows :

---
spring:
  profiles: currentProfile
  profiles.include: profileToInclude

That way it's not a complex structure to parse and both keys exist.

Upvotes: 5

Biju Kunjummen
Biju Kunjummen

Reputation: 49915

This appears to be a restriction with the SnakeYAML parser and the way Spring Boot uses it. Since yaml allows multiple distinct documents to be specified in a single file with a --- separator, the way Spring separates out separate documents is by the spring.profiles key, this key is expected to be a simple structure and not a complex structure unfortunately.

A good workaround is actually to split this into multiple files this way:

application.yaml with common content, application-<profile> with profile specific extensions, with this structure in place key spring.profiles.include will work as expected.

Upvotes: 8

Related Questions