-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathAppCommandLineRunner.java
More file actions
40 lines (34 loc) · 1.31 KB
/
AppCommandLineRunner.java
File metadata and controls
40 lines (34 loc) · 1.31 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
37
38
39
40
package org.prgms.kdtspringweek1;
import org.prgms.kdtspringweek1.controller.consoleController.AppController;
import org.prgms.kdtspringweek1.exception.ExitException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
@Component
@Profile({"console"})
public class AppCommandLineRunner implements CommandLineRunner {
private boolean shouldExit = false;
private final AppController appController;
private static final Logger logger = LoggerFactory.getLogger(AppCommandLineRunner.class);
public AppCommandLineRunner(AppController appController) {
this.appController = appController;
}
@Override
public void run(String... args) {
while (!shouldExit) {
try {
appController.startVoucherProgram();
} catch (ExitException exception) {
// 시스템이 종료되어야하는 예외를 구분하여 처리
System.out.println(exception.getMessage());
logger.error(exception.getMessage());
shouldExit = true;
}
}
}
public void setShouldExit(boolean shouldExit) {
this.shouldExit = shouldExit;
}
}