Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 985
ndrone Avatar asked Feb 12 '16 21:02

ndrone


2 Answers

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.

like image 142
Biju Kunjummen Avatar answered Oct 09 '22 22:10

Biju Kunjummen


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.

like image 44
Tom Avatar answered Oct 09 '22 23:10

Tom