Quick revision
The short answer
I would recommend one artifact for all environments, with environment differences supplied at deployment time, because profiles baked into the jar tie the artifact to known environments and hide differences inside a build. Profiles still have a place for feature sets and local development. The rule should be short and written down so teams do not mix approaches, and existing services should be cleaned up gradually rather than in one large migration.
What to remember
In this answer, we saw that environment profiles baked into the jar tie the artifact to known environments, need a rebuild for every value change and hide differences between environments. Deployment-time configuration keeps one artifact for every environment with the differences explicit and reviewed where the deployment lives. Profiles remain useful for local development and feature sets, the rule must be simple and documented so teams do not mix approaches, and existing services are cleaned up gradually with before-and-after checks.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would recommend one artifact for all environments, with environment differences supplied at deployment time, because profiles baked into the jar tie the artifact to known environments and hide differences inside a build. Profiles still have a place for feature sets and local development. The rule should be short and written down so teams do not mix approaches, and existing services should be cleaned up gradually rather than in one large migration.
Why this question is asked
For a long time the standard Spring answer to different environments was a profile per environment: application-dev.yml, application-qa.yml, application-prod.yml, all packaged into the jar, with the right profile switched on at startup. Many organisations have moved away from this towards configuration supplied by the deployment platform. Interviewers ask senior leaders this question because the recommendation will shape hundreds of services for years, and because it needs a clear reason, not just a preference. In this answer, we will recap the two approaches, look at what goes wrong with environment profiles in the jar, see why deployment-time configuration ages better, keep the uses where profiles still fit, and plan the rule and the cleanup.
1A Quick Recap of the Two Approaches
With environment profiles, the jar contains a file for each environment, and starting it with SPRING_PROFILES_ACTIVE=prod makes Spring Boot load application-prod.yml on top of application.yml. The knowledge of what production looks like, its URLs, pool sizes and timeouts, lives inside the build.
With deployment-time configuration, the jar contains only defaults that are safe everywhere, and each environment supplies its own differences when it deploys the service: environment variables in a Helm values file, a ConfigMap mounted as a config tree, or a file in a GitOps repository. The jar knows nothing about specific environments.
| Question | Profiles in the jar | Deployment-time config |
|---|---|---|
| New environment | new profile file, new build | new values file, same build |
| Change a prod value | rebuild and redeploy the jar | change config, roll out |
| Where are prod values seen? | inside the source repository | next to the deployment, reviewed there |
| Same artifact everywhere? | same jar, different behaviour per profile | same jar, differences explicit |
| Risk of hidden differences | high: profile files drift | low: one place per environment |
2What Goes Wrong With Environment Profiles in the Jar
The first problem is coupling. The artifact knows a fixed list of environments, so adding a new one, a load test environment or a new region, means changing the code and building again. And a value change for production, such as a larger pool, needs a full build, even though no code changed.
The second problem is hidden differences. Over years, application-qa.yml and application-prod.yml drift apart in ways nobody intended: a timeout changed in one and not the other, a feature enabled only in qa. Because the files are packaged, the difference is invisible to whoever operates the environment, and the claim that we tested the same artifact becomes weaker, since the jar behaves differently in each environment. Many hard production bugs come from such a difference.
3Why Deployment-Time Configuration Ages Better
Keeping one artifact for every environment, with differences supplied at deployment, makes the differences explicit and puts them where the people running the environment can see and review them. A new environment is a new values file, not a new build. A production value change goes through the deployment pipeline, with review and rollout, but without rebuilding the code.
This also matches how platforms are heading. Kubernetes, GitOps tools and secret stores all deliver configuration from outside the image, and container images are increasingly signed and promoted unchanged from one environment to the next. An approach that treats the image as immutable and the configuration as deployment data fits that direction for the next decade.
4Where Profiles Still Fit
This is not a rule against profiles. A profile is still a good tool when it describes a kind of runtime rather than a specific environment. A local profile for developer machines can switch on Docker Compose support, test containers or a simpler security setup. A profile for a feature set that ships in some products and not others, or for a test slice, can be fine too.
The test is simple: if the profile's name is the name of a place where we deploy, such as qa, prod or eu-west, it should probably be deployment configuration. If it names a way of running, such as local or a capability bundle, it can stay a profile.
- Does it name a deployment environment?qa, stage, prod, a regionYesUse deployment-time configurationNoContinue
- Does it describe a way of running?local, test, a feature bundleYesA profile is fineNoUse an explicit property
2 steps in order. Play them, or step through them one at a time.
5Making the Rule Stick and Cleaning Up
A recommendation only works if teams can follow it without a debate each time, so I would write it as a one-page standard with an example service: defaults in application.yml, differences in deployment values, profiles only for local and named feature bundles. Mixing approaches is the worst outcome, because then nobody knows whether a value comes from a profile file or the deployment, so the standard should say clearly which one wins for new services.
For existing services I would plan a gradual cleanup rather than a migration project. When a team next touches a service, it moves the values from application-prod.yml into the deployment values, compares the Actuator env output before and after to prove nothing changed, and deletes the file. A simple report of how many services still contain environment profile files shows progress each quarter. Over a year or two the number falls without any team being stopped for a big migration.
6Follow-up questions
Does deployment-time configuration mean thousands of environment variables?
Not necessarily. Environment variables suit a handful of values; larger sets are better as a mounted file or config tree imported with spring.config.import, which keeps structure and is still supplied by the deployment, not the jar.
What about teams that like seeing all environments in one repository?
They can still have that: the GitOps repository holds the values for every environment side by side, which is even better for review than profile files in the code repository, because it sits next to the rest of the deployment.
How do you stop the defaults in the jar from becoming a hidden environment?
Defaults must be safe and boring, for example local addresses and small pools, and required production values should have no default at all, so validation fails at startup if the deployment forgets them.
7Conclusion
In this answer, we saw that environment profiles baked into the jar tie the artifact to known environments, need a rebuild for every value change and hide differences between environments. Deployment-time configuration keeps one artifact for every environment with the differences explicit and reviewed where the deployment lives. Profiles remain useful for local development and feature sets, the rule must be simple and documented so teams do not mix approaches, and existing services are cleaned up gradually with before-and-after checks.
Open with
I would recommend one artifact for all environments, with every environment difference supplied at deployment time. Environment profiles baked into the jar, like application-prod.yml, tie the build to a fixed list of environments.
Then, if they want more
A new environment or a changed production value needs a new build, and over the years the profile files drift apart in ways nobody sees, so the same jar quietly behaves differently in qa and prod.
With deployment-time configuration, the jar holds only safe defaults, and each environment's differences live in its deployment values, environment variables or a mounted config tree, reviewed in the GitOps repository next to the rest of the deployment. The same image can then be promoted unchanged from one environment to the next, which is where container platforms are heading anyway.
I would not ban profiles. They still fit for ways of running, like a local profile for developer machines with Docker Compose support, or a named feature bundle. My test is whether the profile name is a place we deploy to. If it is, it should be deployment configuration.
I would write the rule as a short standard with an example service so teams do not mix approaches. Then I would clean up gradually: when a team touches a service, it moves the profile values into the deployment, compares the env endpoint before and after, and deletes the file, and we track the count each quarter.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Boot reference
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Profiles were once the main way to configure Spring applications per environment, and...": https://scrivio-interview-library.netlify.app/spring-boot/externalized-configuration/2a75b68933/