-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Consider what to do about environment variable clashes #3427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@dsyer @wilkinsona Seems like a sensible change for 1.2.x. Any objections? |
Is that really fixing the underlying issue? I mean, we could have the same kind of scenario with virtually anything, right? Of course, |
Seems like a reasonable step for 1.2.6 though. I was never very comfortable that we didn't use ignoreUnknownFields=false more (it's a valuable feature). So for 1.3 maybe we could do something more thorough? |
I don't like it. The proposed change would mean that everyone loses the assurance that their configuration keys match up just to address a conflict in one person's environment. Perhaps we have no choice, though – |
cough cough |
Hmm, we almost want |
Not really, you get auto-completion in the IDE now so the only places really when you need some kind of safety net are System property, OS env variable or command line switch. And this is even more true when you start to deviate from the canonical format. I'd actually argue for the opposite. Of course, that doesn't help here :( |
For me one of the main benefits of having an |
@wilkinsona, I couldn't agree more! |
Hi, I've put a considerable amount of thought into this topic, and since it recently affected me personally (see #3775) I feel it's time to share my thoughts and concerns. Summary: Spring Boot's opinionated view of the world of Spring is great! But... that opinionated view simply must not extend beyond the boundaries of a Spring application since the consequence is a guaranteed recipe for disaster. Rationale: In retrospect, it was an unfortunate design decision to bind Spring Boot configuration properties to non-prefixed variables in the environment. Spring Boot knows how a Spring application should be best configured; but Spring Boot does not know how the enclosing environment (server, developer workstation, container, etc.) should be best configured. In fact, Spring Boot should not make any assumptions about or place any restrictions on the environment in which a Spring Boot application is deployed. Any attempt to do so will make Spring Boot deployments fragile at best, likely hindering adoption in certain companies. As a concrete example, let's assume that we are developing a Spring Boot based web application that will start an embedded Tomcat server on deployment. We would like for this fat JAR to be able to be deployed in various environments, even if we are not in control of the deployment environments. We therefore cannot place any restrictions on the presence of environment variables already present in such a deployment environment. The system administrator or operations team may deem it necessary to define environment variables such as Essentially, if a sysadmin needs to define We can learn a lesson from the core Spring Framework here: when we introduced support for environment profiles several years ago, we decided to introduce a The same arguments hold true for Spring Boot: Spring Boot cannot presume that it is the only application in the world that would define an environment variable named The only viable solution to make Spring Boot a good citizen within the world of IT is to introduce a prefix specific to Spring Boot (proposal: "spring.boot."): for example, That's how I see it, and I hope we can come up with a workable solution for this topic in time for Spring 1.3 GA! Regards, Sam |
Would #3450 cover some of the concerns? |
@spencergibb, #3450 would be one option, but it's limited in its applicability since it requires that a developer be aware of the problem to begin with. My goal is that all Spring Boot applications (including those created by developers new to Spring Boot with wizards like http://start.spring.io/) should work without modification regardless of what environment variables are present but unrelated to Spring Boot. |
We talked about this a bit on today's Boot team call. Neither prefixing everything nor #3450 are good solutions for 1.3:
Our current plan is to investigate offering two different levels of strictness when binding configuration properties. The current behaviour (in 1.3.0.M4) blows up if a property from any source cannot be bound and |
Agreed! I vote for that change in 2.0 with a viable migration path in the interim.
That sounds very sensible. If you don't add a "less strict level" that is used by default in the 1.3 timeline, I would recommend a command-line option for disabling failure for unsupported properties pulled in via environment variables plus the proposed diagnostic improvements in #3778. That combination would at least give developers a clue as to what went wrong and a means to fix it (without having to modify either their app or their existing environment). Cheers, Sam |
It seems good to have a prefix for only system environment source, not for the other sources like application.properties. system env is the place where some conflict can happen with other application also. even there can be two boot application running in a machine will require different value to be set in ENV but any other source can be installation specific. |
Moving this one to 1.3.x (although I don't know that we'll get to it) and opening #3903 to track a simpler fix for 1.2.x. |
See #3903 (comment) for an another example of the problem. |
This looks like a duplicate of #3450. Feel free to reopen if that is not the case. |
When running a Spring Boot application on a server that has any environment variable with a prefix of "SERVER_", the ServerProperties class will attempt to use it as a property and subsequently break due to the
ignoreUnknownFields = false
annotation...Is it possible to configure the ServerProperties class to have
ignoreUnkownFields = true
instead (as this seems like the situation that it was designed for)?Otherwise is there another way around the issue, bearing in mind that I'm currently using the environment variable SPRING_PROFILES_ACTIVE to control which type of environment the app should be running as (dev, stage, prod, etc).
The text was updated successfully, but these errors were encountered: