Spring profile includes a problem with yaml file

I try to execute when the command 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 get the following error

Called: Display values ​​are not allowed here in line "reader", line 28, column 12: include: cloud

+6
source share
2 answers

This is apparently a limitation with the SnakeYAML parser and a way to use w760> Boot. Since yaml allows you to specify several separate documents in a single file with a delimiter --- , the Spring method separates separate documents from the spring.profiles key, this key is expected to be a simple structure, not a complicated structure unfortunately.

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

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

+6
source

After Biju's answer, if you want to save one file with a separator, rather than use separate profile files, you can define the spring.profiles.include key as follows:

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

Thus, it is not a complicated structure for parsing and both keys exist.

0
source

Source: https://habr.com/ru/post/1242913/


All Articles