me.paulschwarz.springdotenv.DotenvPropertyLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spring-dotenv Show documentation
Show all versions of spring-dotenv Show documentation
Provides a Dotenv property source for Spring and Spring Boot
package me.paulschwarz.springdotenv;
import io.github.cdimascio.dotenv.Dotenv;
import io.github.cdimascio.dotenv.DotenvBuilder;
public class DotenvPropertyLoader {
private final Dotenv dotenv;
public DotenvPropertyLoader(DotenvConfig dotenvConfig) {
DotenvBuilder dotenvBuilder = Dotenv.configure();
dotenvConfig.getDirectoryOptional().ifPresent(dotenvBuilder::directory);
dotenvConfig.getFilenameOptional().ifPresent(dotenvBuilder::filename);
dotenvConfig.getIgnoreIfMalformedTruth().ifPresent(value -> dotenvBuilder.ignoreIfMalformed());
dotenvConfig.getIgnoreIfMissingTruth().ifPresent(value -> dotenvBuilder.ignoreIfMissing());
dotenvConfig.getSystemPropertiesTruth().ifPresent(value -> dotenvBuilder.systemProperties());
dotenv = dotenvBuilder.load();
}
public Object getValue(String key) {
return dotenv.get(key);
}
}