#!/usr/bin/env bash # spring.config.import ordering, multi-document activation, and the activation Boot refuses. set -euo pipefail set +m cd "$(dirname "$0")/.." source scripts/env.sh { echo "== spring.config.import: which document wins? ==" echo echo "application-import.yaml imports imported.yaml. Both set demo.greeting." echo "\$ java -jar $JAR --spring.profiles.active=import" echo start_app --spring.profiles.active=import > /dev/null report demo.greeting echo echo " demo.imported-only = $(curl -s "http://127.0.0.1:${APP_PORT}/precedence?name=demo.imported-only" | python3 -c 'import json,sys; print(json.load(sys.stdin)["effectiveValue"])')" echo echo "The imported file WON. spring.config.import does not behave like #include, and it" echo "does not behave like a default either: the imported document is processed AFTER the" echo "document that declared the import, so it outranks the file that pulled it in." echo "If you import a shared baseline expecting your own file to override it, every key" echo "the baseline sets will quietly beat yours." echo echo "== one file, several documents, activated by condition ==" for profile in "" staging prod; do label="${profile:-}" echo "--- spring.profiles.active=$label (with the multidoc profile) ---" if [ -z "$profile" ]; then start_app --spring.profiles.active=multidoc > /dev/null else start_app --spring.profiles.active="multidoc,$profile" > /dev/null fi report demo.greeting echo done echo "Later documents in the same file win over earlier ones, so the unconditional first" echo "document acts as the default and each conditional document overrides it." echo echo "== the activation Spring Boot refuses ==" echo "application-badactivation.yaml tries to set spring.profiles.active from a document" echo "that is itself conditional on a profile." echo "\$ java -jar $JAR --spring.profiles.active=badactivation,staging" echo stop_app java -jar "$JAR" --spring.profiles.active=badactivation,staging 2>&1 | clean \ | grep -E 'InvalidConfigDataPropertyException' | head -2 | fold -s -w 96 echo echo echo "InvalidConfigDataPropertyException, naming the file and the line. Boot refuses" echo "rather than half-applying it: a profile that activates itself would change which" echo "files are loaded after those files had already been chosen." } > docs/output/04-import-and-multidoc.txt 2>&1 cat docs/output/04-import-and-multidoc.txt