Video in progress

What is externalized configuration, and why shouldn't you keep configuration inside the code?

Configuration (URLs, limits, feature flags) is kept outside the code: in environment variables, a config server or a Kubernetes ConfigMap. That way a single built artifact runs unchanged in dev, test and prod.

📖 Answer

The wrong approach is a separate build for each environment: app-dev.jar, app-prod.jar. What you tested in the test environment is no longer the same as what goes to prod.

The right approach is one image, with settings passed in from outside depending on the environment:

# application.yml — default values
payment:
  base-url: ${PAYMENT_URL:http://localhost:8081}
  timeout: ${PAYMENT_TIMEOUT:3s}
@ConfigurationProperties(prefix = "payment")
record PaymentProperties(URI baseUrl, Duration timeout) {}

Spring Boot gets configuration from many sources and there's a precedence order: an environment variable overrides the value in application.yml. If you set PAYMENT_TIMEOUT=5s, the new value takes effect without changing the code.

When you have many services, there are central options too: Spring Cloud Config Server, Consul, Kubernetes ConfigMap. You can change something in one place and distribute it to the services that need it.