Skip to content

Commit 4a663ce

Browse files
committed
refactor(config): clean up main class and integrate DotenvInitializer properly
1 parent 0e2b7a9 commit 4a663ce

1 file changed

Lines changed: 5 additions & 25 deletions

File tree

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,15 @@
11
package com.example.spring_boot_project;
22

3-
import io.github.cdimascio.dotenv.Dotenv;
43
import org.springframework.boot.SpringApplication;
54
import org.springframework.boot.autoconfigure.SpringBootApplication;
65

6+
import com.example.spring_boot_project.config.DotenvInitializer;
7+
78
@SpringBootApplication
89
public class SpringBootProjectApplication {
910
public static void main(String[] args) {
10-
Dotenv dotenv = Dotenv.configure()
11-
.ignoreIfMissing()
12-
.load();
13-
14-
setSystemPropertyIfPresent(dotenv, "ADMIN_USERNAME");
15-
setSystemPropertyIfPresent(dotenv, "ADMIN_PASSWORD");
16-
setSystemPropertyIfPresent(dotenv, "JWT_SECRET_KEY");
17-
setSystemPropertyIfPresent(dotenv, "SERVER_COMPRESSION_MIN_RESPONSE_SIZE");
18-
19-
SpringApplication.run(SpringBootProjectApplication.class, args);
20-
}
21-
22-
/**
23-
* verify system property if present
24-
*
25-
* @param dotenv
26-
* @param key
27-
* @return void
28-
*/
29-
private static void setSystemPropertyIfPresent(Dotenv dotenv, String key) {
30-
String value = dotenv.get(key);
31-
if (value != null) {
32-
System.setProperty(key, value);
33-
}
11+
SpringApplication app = new SpringApplication(SpringBootProjectApplication.class);
12+
app.addInitializers(new DotenvInitializer());
13+
app.run(args);
3414
}
3515
}

0 commit comments

Comments
 (0)