-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathDotenvConfig.java
More file actions
36 lines (33 loc) · 1.28 KB
/
DotenvConfig.java
File metadata and controls
36 lines (33 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package greencity.config.dotenv;
import greencity.constant.AppConstant;
import greencity.constant.ErrorMessage;
import greencity.exception.exceptions.FunctionalityNotAvailableException;
import io.github.cdimascio.dotenv.Dotenv;
import io.github.cdimascio.dotenv.DotenvException;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Primary;
@Configuration
@Lazy
public class DotenvConfig {
@Bean
@ConditionalOnMissingBean(Dotenv.class)
public Dotenv fallbackDotenv() {
return Dotenv.configure().ignoreIfMissing().load();
}
@Bean
@ConditionalOnExpression("#{T(greencity.config.dotenv.DotEnvConditionChecker).isEnabled()}")
@Primary
Dotenv dotenv() {
try {
return Dotenv.configure()
.filename(AppConstant.DOTENV_FILENAME)
.load();
} catch (DotenvException ignored) {
throw new FunctionalityNotAvailableException(ErrorMessage.FUNCTIONALITY_NOT_AVAILABLE);
}
}
}