8

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

Andremoniy
  • 31,241
  • 14
  • 110
  • 218
ndrone
  • 3,114
  • 1
  • 18
  • 33
  • Tried to remove the ` ` in front of `include` ? – Marged Feb 14 '16 at 22:19
  • @Marged so that `include` is not nested in `profiles`? – ndrone Feb 14 '16 at 22:21
  • Had a look at this ? http://stackoverflow.com/questions/25985752/including-profiles-with-spring-profiles-include-seems-to-override-instead-of-inc. Which version of Spring do you use ? – Marged Feb 14 '16 at 22:32
  • I was first looking at that post, but that isn't giving me the results I'm looking for. I only want `cloud` when `wesphere` is active. If make chnage the `websphere` profile to --- spring: profiles: active: websphere include: cloud test: websphere . It always loads the `cloud` profile. I'm using spring 4.2 and spring boot 1.3.1 – ndrone Feb 14 '16 at 23:12
  • Try an update to 1.3.2 and check if a classic application.properties does the job – Marged Feb 14 '16 at 23:24
  • @Marged already tried that and works of course, but doesn't with the yaml file. Must be a limitation with yaml then? – ndrone Feb 14 '16 at 23:28
  • Which of the two suggestions ? Ever thought of specifying two profiles ? Would this be viable ? – Marged Feb 14 '16 at 23:30
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/103444/discussion-between-ndrone-and-marged). – ndrone Feb 14 '16 at 23:36

2 Answers2

8

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.

Biju Kunjummen
  • 45,973
  • 14
  • 107
  • 121
5

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.

Tom
  • 51
  • 1
  • 2