Code Monkey home page Code Monkey logo

dotenv-java's Introduction

🗝️ dotenv-java

Build Status Maven Central Codacy Badge All Contributors

A no-dependency, pure Java port of the Ruby dotenv project. Load environment variables from a .env file.

dotenv

dotenv-java also powers the popular dotenv-kotlin library.

Why dotenv?

Storing configuration in the environment is one of the tenets of a twelve-factor app. Anything that is likely to change between deployment environments–such as resource handles for databases or credentials for external services–should be extracted from the code into environment variables.

But it is not always practical to set environment variables on development machines or continuous integration servers where multiple projects are run. Dotenv load variables from a .env file into ENV when the environment is bootstrapped.

-- Brandon Keepers

Environment variables listed in the host environment override those in .env.

Use dotenv.get("...") instead of Java's System.getenv(...).

Install

Requires Java 11 or greater.

Still using Java 8? Use version 2.3.2

Maven

<dependency>
    <groupId>io.github.cdimascio</groupId>
    <artifactId>dotenv-java</artifactId>
    <version>3.0.0</version>
</dependency>

Gradle <4.10

compile 'io.github.cdimascio:dotenv-java:3.0.0'

Gradle >=4.10

implementation 'io.github.cdimascio:dotenv-java:3.0.0'

Gradle Kotlin DSL

implementation("io.github.cdimascio:dotenv-java:3.0.0")

Looking for the Kotlin variant? get dotenv-kotlin.

Usage

Use dotenv.get("...") instead of Java's System.getenv(...). Here's why.

Create a .env file in the root of your project

# formatted as key=value
MY_ENV_VAR1=some_value
MY_EVV_VAR2=some_value #some value comment
Dotenv dotenv = Dotenv.load();
dotenv.get("MY_ENV_VAR1")

Android Usage

  • Create an assets folder

  • Add env (no dot) to the assets folder

  • Configure dotenv to search /assets for a file with name env

     Dotenv dotenv = Dotenv.configure()
        .directory("/assets")
        .filename("env") // instead of '.env', use 'env'
        .load();
    
     dotenv.get("MY_ENV_VAR1");

Note: The above configuration is required because dot files in /assets do not appear to resolve on Android. (Seeking recommendations from the Android community on how dotenv-java configuration should work in order to provide the best experience for Android developers)

Alternatively, if you are using Provider android.resource you may specify

 .directory("android.resource://com.example.dimascio.myapp/raw")

Advanced Usage

Configure

Configure dotenv-java once in your application.

Dotenv dotenv = Dotenv.configure()
        .directory("./some/path")
        .ignoreIfMalformed()
        .ignoreIfMissing()
        .load();

Get environment variables

Note, environment variables specified in the host environment take precedence over those in .env.

dotenv.get("HOME");
dotenv.get("MY_ENV_VAR1", "default value");

Iterate over environment variables

Note, environment variables specified in the host environment take precedence over those in .env.

for (DotenvEntry e : dotenv.entries()) {
    System.out.println(e.getKey());
    System.out.println(e.getValue());
}

Configuration options

optional directory

  • path specifies the directory containing .env. Dotenv first searches for .env using the given path on the filesystem. If not found, it searches the given path on the classpath. If directory is not specified it defaults to searching the current working directory on the filesystem. If not found, it searches the current directory on the classpath.

    example

     Dotenv
       .configure()
       .directory("/some/path")
       .load();

optional filename

  • Use a filename other than .env. Recommended for use with Android (see details)

    example

     Dotenv
       .configure()
       .filename("myenv")
       .load();

optional ignoreIfMalformed

  • Do not throw when .env entries are malformed. Malformed entries are skipped.

    example

     Dotenv
       .configure()
       .ignoreIfMalformed()
       .load();

optional ignoreIfMissing

  • Do not throw when .env does not exist. Dotenv will continue to retrieve environment variables that are set in the environment e.g. dotenv["HOME"]

    example

     Dotenv
       .configure()
       .ignoreIfMissing()
       .load();

optional systemProperties

  • Load environment variables into System properties, thus making all environment variables accessible via System.getProperty(...)

    example

     Dotenv
       .configure()
       .systemProperties()
       .load();

Examples

Powered by dotenv-java

see javadoc

FAQ

Q: Should I deploy a .env to e.g. production?

A: Tenant III of the 12 factor app methodology states "The twelve-factor app stores config in environment variables". Thus, it is not recommended to provide the .env file to such environments. dotenv, however, is super useful in e.g a local development environment as it enables a developer to manage the environment via a file which is more convenient.

Using dotenv in production would be cheating. This type of usage, however is an anti-pattern.

Q: Why should I use dotenv.get("MY_ENV_VAR") instead of System.getenv("MY_ENV_VAR")

A: Since Java does not provide a way to set environment variables on a currently running process, vars listed in .env cannot be set and thus cannot be retrieved using System.getenv(...).

Q: Can I use System.getProperty(...) to retrieve environment variables?

A: Sure. Use the systemProperties option. Or after initializing dotenv set each env var into system properties manually. For example:

example

Dotenv dotenv = Dotenv.configure().load();
dotenv.entries().forEach(e -> System.setProperty(e.getKey(), e.getValue()));
System.getProperty("MY_VAR");

Q: Should I have multiple .env files?

A: No. We strongly recommend against having a "main" .env file and an "environment" .env file like .env.test. Your config should vary between deploys, and you should not be sharing values between environments.

In a twelve-factor app, env vars are granular controls, each fully orthogonal to other env vars. They are never grouped together as “environments”, but instead are independently managed for each deploy. This is a model that scales up smoothly as the app naturally expands into more deploys over its lifetime.

– The Twelve-Factor App

Q: Should I commit my .env file?

A: No. We strongly recommend against committing your .env file to version control. It should only include environment-specific values such as database passwords or API keys. Your production database should have a different password than your development database.

Q: What happens to environment variables that were already set?

A: dotenv-java will never modify any environment variables that have already been set. In particular, if there is a variable in your .env file which collides with one that already exists in your environment, then that variable will be skipped. This behavior allows you to override all .env configurations with a machine-specific environment, although it is not recommended.

Q: What about variable expansion in .env?

A: We haven't been presented with a compelling use case for expanding variables and believe it leads to env vars that are not "fully orthogonal" as The Twelve-Factor App outlines. Please open an issue if you have a compelling use case.

Q: Can I supply a multi-line value?

A: dotenv-java exhibits the same behavior as Java's System.getenv(...), thus if a multi-line value is needed you might consider encoding it via e.g. Base64. see this comment for details.

Note and reference: The FAQs present on motdotla's dotenv node project page are so well done that I've included those that are relevant in the FAQs above.

see CONTRIBUTING.md

License

see LICENSE (Apache 2.0)

Buy Me A Coffee

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Clement Cherlin
Clement Cherlin

💻 ⚠️
Alex Braga
Alex Braga

📖
Alexey Venderov
Alexey Venderov

💻
yassenb
yassenb

💻
Sidney Beekhoven
Sidney Beekhoven

💻 📖
Manoel Campos
Manoel Campos

💻 ⚠️ 🚇

This project follows the all-contributors specification. Contributions of any kind welcome!

dotenv-java's People

Contributors

alexbraga avatar allcontributors[bot] avatar c00ler avatar cdimascio avatar clintval avatar dizney avatar manoelcampos avatar mooninaut avatar nuriofernandez avatar paulschwarz avatar yassenb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

dotenv-java's Issues

the README.md android example is slightly wrong

 Dotenv dotenv = Dotenv.configure()
    .directory("/assets")
    .filename("env"); // instead of '.env', use 'env'

 dotenv.get("MY_ENV_VAR1");

should be

Dotenv dotenv = Dotenv.configure()
   .directory("/assets")
   .filename("env").load(); // instead of '.env', use 'env'

dotenv.get("MY_ENV_VAR1");

thanks for your work, PS: did you ever get to the bottom of the .env filename thing?

Why .env variables not working in applicatio.properties file

I have added dependency in build.gradle
implementation 'io.github.cdimascio:dotenv-java:2.3.2'

MyApplication.java


@SpringBootApplication
public class MovieApiApplication {
public static void main(String[] args) {
Dotenv dotenv = Dotenv.load();
String myEnvVar = dotenv.get("MONGO_CLUSTER");
System.out.println(myEnvVar);

SpringApplication.run(MovieApiApplication.class, args);

}
}
above code works but,

application.properties


spring.data.mongodb.database=${env:MONGO_DATABASE}
spring.data.mongodb.uri=mongodb+srv://${env:MONGO_USER}:${env:MONGO_PASSWORD}@${env:MONGO_CLUSTER}

above code is not working as compiler is not able to resolve above env variables

StringIndexOutOfBoundsException for broken .env file while using ignoreIfMalformed

I use this deliberately really broken .env file to test stuff, and dotenv-java crashes with an StringIndexOutOfBoundsException on it. Is the ignoreIfMalformed option supposed to catch these or is this out of scope for this library?

FOO="

The problem is that isQuoted() checks if the value starts and ends with ", but not that it is longer than a single character, and later normalizeValue() tries to slice of a character from the start and end.

Backtrace:

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: begin 1, end 0, length 1
        at java.base/java.lang.String.checkBoundsBeginEnd(String.java:4601)
        at java.base/java.lang.String.substring(String.java:2704)
        at io.github.cdimascio.dotenv.internal.DotenvParser.normalizeValue(DotenvParser.java:99)
        at io.github.cdimascio.dotenv.internal.DotenvParser.addNewEntry(DotenvParser.java:81)
        at io.github.cdimascio.dotenv.internal.DotenvParser.parse(DotenvParser.java:63)
        at io.github.cdimascio.dotenv.DotenvBuilder.load(DotenvBuilder.java:76)
        at dotenv.Main.main(Main.java:31)

Why even after using load() I can't use env variables in application.properties file

I have added dependency in build.gradle
implementation 'io.github.cdimascio:dotenv-java:2.3.2'

MyApplication.java


@SpringBootApplication
public class MovieApiApplication {
public static void main(String[] args) {
Dotenv dotenv = Dotenv.load();
String myEnvVar = dotenv.get("MONGO_CLUSTER");
System.out.println(myEnvVar);

	SpringApplication.run(MovieApiApplication.class, args);
}

}

spring.data.mongodb.database=${env:MONGO_DATABASE}
spring.data.mongodb.uri=mongodb+srv://${env:MONGO_USER}:${env:MONGO_PASSWORD}@${env:MONGO_CLUSTER}

a

I'm curious...

Imagine just 5 minutes that i would like to get around your strong advice to not use multiple dotenv files :)
Imagine just 5 minutes that i would like to have a .env.dist overriden by an optionnal .env
Just.. imagine...

How would i do ? 😘😘😘

java.lang.NoClassDefFoundError: io/github/cdimascio/dotenv/Dotenv

[01:25:02 ERROR]: Error occurred while enabling SkJson v1.0-SNAPSHOT (Is it up to date?)
java.lang.NoClassDefFoundError: io/github/cdimascio/dotenv/Dotenv
at cz.coffee.SkJson.onEnable(SkJson.java:125) ~[skJson-legacy-1.0-SNAPSHOT-all.jar:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[purpur-api-1.19.3-R0.1-SNAPSHOT.jar:?]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:372) ~[purpur-api-1.19.3-R0.1-SNAPSHOT.jar:?]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:550) ~[purpur-api-1.19.3-R0.1-SNAPSHOT.jar:?]
at org.bukkit.craftbukkit.v1_19_R2.CraftServer.enablePlugin(CraftServer.java:624) ~[purpur-1.19.3.jar:git-Purpur-1864]

I got everything right, but this is still happening.

dependencies {
    compileOnly 'com.destroystokyo.paper:paper-api:1.16.5-R0.1-SNAPSHOT'
    compileOnly 'org.projectlombok:lombok:1.18.24'
    compileOnly 'org.jetbrains:annotations:23.1.0'
    compileOnly 'com.github.SkriptLang:Skript:2.6.3'

    implementation group: 'org.eclipse.jdt', name: 'org.eclipse.jdt.annotation', version: '2.2.700'
    implementation group: 'org.yaml', name: 'snakeyaml', version: '1.33'
    implementation("io.github.cdimascio:dotenv-java:2.3.1")

    //testImplementation(shadow('com.google.code.gson:gson:2.10'))
    //testImplementation('com.destroystokyo.paper:paper-api:1.16.5-R0.1-SNAPSHOT')

    shadow('com.google.code.gson:gson:2.10')
}

Question about the path

Where do I need to create the .env file?
I tried in the following directories but I'm still getting io.github.cdimascio.dotenv.DotenvException: Could not find /.env on the classpath:

  • life-plugin
  • src
  • main
  • lifeplugin (the one with the java file)
    image

Add module-info to the project

It would be very nice if this library added the module-info class.
It is possible to use the Moditect plugin to add to a jar that targets Java 8

JPMS support

Option 1 - Use module-info and make it a fully modular build
Option 2 - Use Automatic-Module-Name in the MANIFEST to reserve the name and make it usable at the very least
... - Any more complicated approach via Moditect

NoClassDefFoundError

java.lang.NoClassDefFoundError: io/github/cdimascio/dotenv/Dotenv

`
public final class PostgreDbConfig {

private final String dbUri;
private final String dbUser;
private final String dbPassword;
private final String dbDriver;

private static PostgreDbConfig instance;

public static PostgreDbConfig getInstance() {
    if (Objects.isNull(instance)) {
        instance = new PostgreDbConfig();
        return instance;
    }
    return instance;
}

@SneakyThrows
private PostgreDbConfig() {
    Dotenv dotenv = Dotenv.configure()
            .directory(PostgreDbConfig.class.getResource("/.env").getPath())
            .load();
    dbUser = dotenv.get("db.uri");
    dbPassword = dotenv.get("db.user");
    dbUri = dotenv.get("db.password");
    dbDriver = dotenv.get("db.driver");

    try {
        Class.forName(dbDriver);
    } catch (ClassNotFoundException e) {
        throw new SQLException(dbDriver + " Driver is not found.");
    }
}

public Connection getConnection() throws SQLException {
    String url = "jdbc:postgresql://localhost/test";
    Properties props = new Properties();
    props.setProperty("user", "fred");
    props.setProperty("password", "secret");

    return DriverManager.getConnection(url, props);
}

}
`

how to solve it?

Support for Java 8?

I have a little request: Can this awesome library add Java 8 as minimum version?
Unfortunately I want to use the library in a project that is using Java 8.
Can this be achieved?
Thanks in advance

Cannot resolve symbol 'github'

I'm getting the following error when trying to use this dependency

Cannot resolve symbol 'github'

I get the error above in this line of code:
Java class
import io.github.cdimascio.dotenv.Dotenv;

pom.xml

<dependency>
    <groupId>io.github.cdimascio</groupId>
    <artifactId>java-dotenv</artifactId>
    <version>5.2.2</version>
</dependency>

In my terminal I ran:

mvn package
mvn dependency:resolve
mvn clean install

I'm new to Java and Maven and based on my small knowledge those commands above should help me install dependencies. Am I missing something?

NoSuchMethodError: java.lang.String.isBlank()Z

My .env contains

GOOD_BOY=Fluffy
NOT_SO_GOOD=Killer

I'm accessing it with

public class KeyLoaderListener implements ServletContextListener {
   private ServletContext context = null;
   private Dotenv dotenv;

   public KeyLoaderListener() {
      this.dotenv = Dotenv.load();   // Line 30 where error occurs
   }
   ...
}

And getting this error

java.lang.NoSuchMethodError: java.lang.String.isBlank()Z
at io.github.cdimascio.dotenv.internal.DotenvParser.parse(DotenvParser.java:33)
at io.github.cdimascio.dotenv.DotenvBuilder.load(DotenvBuilder.java:81)
at io.github.cdimascio.dotenv.Dotenv.load(Dotenv.java:33)
at com.mytest.KeyLoaderListener.<init>(KeyLoaderListener.java:30)

Parser change to allow trailing comments breaks passwords with '#' in them.

I upgraded to 2.3.1 and all of a sudden I was unable to connect to my database. After some digging I realized that it was malforming my password when reading it from the .env file. It cut off the rest of the password after the '#'. I think the regex needs to be updated to ensure that it actually is looking at an intended comment.

Could not find ./.env on the file system (working directory:/)

Hi readers

I am setting up this package in my java project, have added dependency and also created a .env file
but when calling configure() as mentioned below

Dotenv dotenv = Dotenv .configure() .load();

I followed your document but i want to use .env file from the root of the project for example : exampleproject/app/.env

and getting this error every time i do

at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2574) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:226) at android.os.Looper.loop(Looper.java:313) at android.app.ActivityThread.main(ActivityThread.java:8757) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067) Caused by: io.github.cdimascio.dotenv.DotenvException: Could not find /.env on the classpath at io.github.cdimascio.dotenv.internal.ClasspathHelper.loadFileFromClasspath(ClasspathHelper.java:25) at io.github.cdimascio.dotenv.internal.DotenvReader.read(DotenvReader.java:55) at io.github.cdimascio.dotenv.internal.DotenvParser.lines(DotenvParser.java:87) at io.github.cdimascio.dotenv.internal.DotenvParser.parse(DotenvParser.java:60) at io.github.cdimascio.dotenv.DotenvBuilder.load(DotenvBuilder.java:76) at com.example.activity.splash.onCreate(Splash.java:33) at android.app.Activity.performCreate(Activity.java:8591) at android.app.Activity.performCreate(Activity.java:8570) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1384) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4150) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4325)  at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)  at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)  at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2574)  at android.os.Handler.dispatchMessage(Handler.java:106)  at android.os.Looper.loopOnce(Looper.java:226)  at android.os.Looper.loop(Looper.java:313)  at android.app.ActivityThread.main(ActivityThread.java:8757)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)  Suppressed: io.github.cdimascio.dotenv.DotenvException: Could not find ./.env on the file system (working directory: /) at io.github.cdimascio.dotenv.internal.DotenvReader.read(DotenvReader.java:60)

I ended up pasting .env file on every root of the project for example project/app/ , project/ , project/app/src ... but nun of that worked. !

Could not resolve placeholder 'SPRING_DATASOURCE_URL' in value "${SPRING_DATASOURCE_URL}"

Hello All,

I'm still facing to this issue after intallation of dotenv-java dependency.

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.dile.company.DileRestApiApplication]; nested exception is java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$EmbeddedDatabaseConfiguration
	at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:609) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassParser.access$800(ConfigurationClassParser.java:110) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGroupingHandler.lambda$processGroupImports$1(ConfigurationClassParser.java:811) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1378) ~[na:na]
	at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGroupingHandler.processGroupImports(ConfigurationClassParser.java:808) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorHandler.process(ConfigurationClassParser.java:779) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:192) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:319) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:236) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:706) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
	at com.dile.company.DileRestApiApplication.main(DileRestApiApplication.java:61) [classes/:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
	at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.2.5.RELEASE.jar:2.2.5.RELEASE]
Caused by: java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$EmbeddedDatabaseConfiguration
	at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:60) ~[spring-boot-autoconfigure-2.2.5.RELEASE.jar:2.2.5.RELEASE]
	at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:108) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:225) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassParser.processMemberClasses(ConfigurationClassParser.java:371) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:271) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:249) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:599) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	... 24 common frames omitted
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'SPRING_DATASOURCE_URL' in value "${SPRING_DATASOURCE_URL}"
	at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:178) ~[spring-core-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:124) ~[spring-core-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:236) ~[spring-core-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:210) ~[spring-core-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.core.env.AbstractPropertyResolver.resolveNestedPlaceholders(AbstractPropertyResolver.java:227) ~[spring-core-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.core.env.PropertySourcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:88) ~[spring-core-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.core.env.PropertySourcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:62) ~[spring-core-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.core.env.AbstractEnvironment.getProperty(AbstractEnvironment.java:535) ~[spring-core-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$EmbeddedDatabaseCondition.getMatchOutcome(DataSourceAutoConfiguration.java:126) ~[spring-boot-autoconfigure-2.2.5.RELEASE.jar:2.2.5.RELEASE]
	at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47) ~[spring-boot-autoconfigure-2.2.5.RELEASE.jar:2.2.5.RELEASE]
	... 30 common frames omitted

My application.properties:

spring.datasource.url=${SPRING_DATASOURCE_URL}
spring.datasource.username=${SPRING_DATASOURCE_USERNAME}
spring.datasource.password=${SPRING_DATASOURCE_PASSWORD}

My .env:

SPRING_DATASOURCE_URL=jdbc:mysql://127.0.0.1:3306/myDb
SPRING_DATASOURCE_USERNAME=root
SPRING_DATASOURCE_PASSWORD=root

Someone can help me please?
Thanks

[Enhancement request] write variable to env file

Hello there,

This is my first post in this repo. If not anything else, big thanks for this very cool project.

I would like to ask if it is possible to start a feature request.
As of right now, it is possible to "read" a env file by doing the dotenv.get("mykey")

Would it be possible to have a feature to write some values?

For instance: starting with the file .env

With content

mykey = somevalue

Then to run dotenv.set("anotherkey", "someothervalue")

And the .env file would be

anotherkey =someothervalue

Hope this is not too much of a trouble.

Thank you

maven-plugin

Hi!

I think a maven plugin would be nice.

<plugin>
  <artifactId>dotenv-maven-plugin</artifactId>
  <configuration>
    <dotEnvFile>${project.basedir}/.env</dotEnvFile>
  </configuration>
</plugin>

If you need help writing a maven plugin, let me know.

java.lang.ClassNotFoundException: kotlin.jvm.internal.Intrinsics

I've brought in version 5.2.2 into a project. I'm not using Maven so I downloaded java-dotenv-5.2.2.jar from the Maven Repo. Running my app results in java.lang.ClassNotFoundException: kotlin.jvm.internal.Intrinsics .

Using version 5.2.1 results in ClassNotFoundException: kotlin.TypeCastException

Are there other dependencies I need to incorporate?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.