Skip to content

Commit 68a4298

Browse files
solve NullPointerPointerException : local env but not present in production
1 parent 6bea8e0 commit 68a4298

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed
Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
package csembstu.alamgir.server.config;
22

33
import io.github.cdimascio.dotenv.Dotenv;
4+
import io.github.cdimascio.dotenv.DotenvEntry;
45

56
public class EnvConfig {
67
public static void loadEnv() {
7-
88
Dotenv dotenv = Dotenv.configure()
99
.ignoreIfMissing()
1010
.load();
1111

12-
String dbhost = dotenv.get("DB_HOST");
13-
String dbport = dotenv.get("DB_PORT");
14-
String dbname = dotenv.get("DB_NAME");
15-
String dbuser = dotenv.get("DB_USER");
16-
String dbpassword = dotenv.get("DB_PASSWORD");
17-
18-
System.setProperty("DB_HOST", dbhost);
19-
System.setProperty("DB_PORT", dbport);
20-
System.setProperty("DB_NAME", dbname);
21-
System.setProperty("DB_USER", dbuser);
22-
System.setProperty("DB_PASSWORD", dbpassword);
12+
for (DotenvEntry entry : dotenv.entries()) {
13+
String key = entry.getKey();
14+
String value = entry.getValue();
2315

16+
if (value != null && !value.isEmpty()) {
17+
System.setProperty(key, value);
18+
}
19+
}
2420
}
25-
}
21+
}

0 commit comments

Comments
 (0)