spring.config.import seems to not be working properly when working with multi-document files (either that or with spring.config.activate.on-profile, not sure who is the culprit).

I have a Spring Boot application that doesn't do anything and has the following application properties files:

application.yaml:

spring.config.import: 'application-overrides.yaml'

server:
  port: 443

---

spring.config.activate.on-profile: 'development'

server:
  port: 8443

application-overrides.yaml:

server:
  port: 9999

> mvn spring-boot:run -Dspring-boot.run.profiles=development runs on port 8443 instead of 9999. The server.port override is not being applied. If I remove the document for spring.config.activate.on-profile: 'development' it will run on port 9999.

According to the documentation, the properties from application-overrides.yaml should override the ones from application.yaml in my example.

I was wondering if doing the following would help but it doesn't:

application-overrides.yaml:

spring.config.activate.on-profile: 'development'

server:
  port: 9999

Comment From: philwebb

I think this is working as expected, although it's quite hard to document exactly how multi-document files work. If you imaging the structure as a tree, you'll get something like this:

+- application.yaml#1 (main document)
|    +- application-override.yaml
+- application.yaml#2 (profile specific document)

The lower elements in the tree override higher ones so you'll get the following port overrides:

  • 443 (application.yaml#1)
  • 9999 (application-override.yaml)
  • 8443 (application.yaml#2 when development is active)

Can you explain a bit more about what you're trying to achieve? Perhaps there's an alternative way to structure your files.

Comment From: joca-bt

We found this by accident. Someone was trying to override the server port in some random machine.

We thought the definition order would be something like:

  1. application.yaml. All its subdocuments from top to bottom order: a. main document b. profile specific document
  2. application-overrides.yaml. It's an import so we thought it would be added after all subdocuments of the file importing it.

The doc mentions and are treated as additional documents inserted immediately below the one that declares the import which we are now finally able to understand what it means. Right below 1a is before 1b. Which means this working as expected; we misunderstood it. If I invert the subdocument definition it works.