#!/usr/bin/env bash # The matrix re-asked the expensive way: one real JVM per spelling, the value supplied by the # operating system or by -D, and read back through both @ConfigurationProperties and @Value. # # This script exists because the in-process matrix was wrong twice before it was right. A # synthesised property source is not a running Spring Boot application, and when the two # disagree the running application wins. set -euo pipefail cd "$(dirname "$0")/.." source scripts/env.sh RUN=(java -jar "$JAR" --spring.profiles.active=envprobe --spring.main.web-application-type=none --spring.main.banner-mode=off --logging.level.root=OFF) run_env() { echo "\$ $1=secret-value java -jar $JAR" env -u DEMO_RELAXED_API_KEY -u DEMO_RELAXED_APIKEY "$1=secret-value" "${RUN[@]}" 2>&1 \ | clean | grep -E "^(env-var-set|@Config|@Value|Environment)" echo } run_sysprop() { echo "\$ java -D$1=secret-value -jar $JAR" env -u DEMO_RELAXED_API_KEY -u DEMO_RELAXED_APIKEY \ java "-D$1=secret-value" -jar "$JAR" --spring.profiles.active=envprobe \ --spring.main.web-application-type=none --spring.main.banner-mode=off \ --logging.level.root=OFF 2>&1 \ | clean | grep -E "^(@Config|@Value|Environment)" echo } { echo "== real process, real environment: binding demo.relaxed.api-key ==" echo echo "canonical property : demo.relaxed.api-key" echo "(MISS) means the property was not found and the declared default was used" echo echo "--- as an operating-system environment variable ---" echo run_env DEMO_RELAXED_API_KEY run_env DEMO_RELAXED_APIKEY echo "--- as a JVM system property (-D), i.e. the 'map' rows of the matrix ---" echo run_sysprop demo.relaxed.api-key run_sysprop demo.relaxed.apiKey run_sysprop demo.relaxed.apikey run_sysprop demo.relaxed.api.key echo "The last one is not a spelling of the property. api.key is two name elements;" echo "api-key is one. Nothing relaxed will ever join them." } > docs/output/02-env-var-binding.txt 2>&1 cat docs/output/02-env-var-binding.txt