The full picture
- Relaxed binding makes env vars work:
SPRING_DATASOURCE_URL↔spring.datasource.url— same property, per-medium naming conventions. - Profile files beat the base file (
application-prod.yml>application.yml), and external files beat packaged ones (./config/application.ymlnext to the jar) — the on-host override escape hatch. - Debugging precedence: don't guess — hit actuator
/env(secured!): it lists every PropertySource in order and which one won for a key. Addspring.config.importand cloud sources (Config Server, K8s ConfigMaps via files) into the same mental stack. - Anti-pattern: baking env-specific values into the jar per environment (a build per env) — breaks the 'same artifact promoted through stages' guarantee your deploy pipeline depends on.
# application.yml (packaged: sane defaults, dev-friendly)
spring.datasource.url: jdbc:postgresql://localhost:5432/app
# application-prod.yml (packaged: prod SHAPE, no secrets)
spring.datasource.hikari.maximum-pool-size: 30
# K8s deployment (environment: values + secrets)
env:
- name: SPRING_PROFILES_ACTIVE
value: prod
- name: SPRING_DATASOURCE_URL
valueFrom: { secretKeyRef: { name: db, key: url } } # wins over both files