-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
Making dotenv variables globally available #2
Comments
Currently, it's not available statically, though its worth consideration. One way to simulate the behavior you are looking for, would be to assign Dotenv to a public static Dotenv ENV = Dotenv.configure().load(); Then can call e.g. |
Hmm yes that does make sense. I was mainly looking for this option because (as you might be able to tell from my other issues: #4, #3) on our project we're going to need some configuration. Having to do this config in every class where the variables are needed seems like it could cause for some issues where one part of the setup is updated but the rest isn't. I had seen some other But I could also abstract this whole |
@jessevdp For now, the the method I recommended above is one possible approach to get ev's via a static helper within your app. |
I build my own little import io.github.cdimascio.dotenv.Dotenv;
public class Config {
private static final Config instance = new Config();
public static Config getConfig () {
return instance;
}
private Dotenv env;
public Config () {
this.env = Dotenv.configure().directory("./").ignoreIfMissing().load();
}
public String get (String variable) {
return env.get(variable);
}
} |
@jessevdp are you using a framework? If not, your Beyond a simple static helper, I'm not sure that java-dotenv should do too much. |
I was wondering if there was any way to make the variables in the
.env
file globally available throughout my entire java application.It seems as though configuring and loading the variables returns a
Map
of sorts from which you can retrieve all of the values. However I have to configure and load this variable in every file from which I wish to use it.Is there any way I can load them once and use them everywhere? Perhaps even through the native
System.getenv()
static method? Running the configuration and loading once from mypublic static main
method or something.The text was updated successfully, but these errors were encountered: