BeanCreationException 예외로 알아보는 빈 생명주기
코드 구현
@Slf4j
@Component
@RequiredArgsConstructor
public class CommandLineExecutor implements CommandLineRunner {
private final ConsoleIOHandler consoleIOHandler;
private final FunctionHandler functionHandler;
private boolean isRunning = true;
@Override
public void run(String... args) {
while (isRunning) {
progress();
}
}
private void progress() {
try {
consoleIOHandler.printMenuTitle(ConsoleConstants.VOUCHER_PROGRAM_START_MESSAGE);
consoleIOHandler.printEnumString(Function.class);
String command = consoleIOHandler.getInputWithPrint();
Function.fromString(command)
.ifPresentOrElse(
function -> function.execute(functionHandler),
() -> {
throw InputException.of(InputErrorMessage.INVALID_COMMAND);
});
} catch (RuntimeException e) {
log.warn(e.getMessage());
} catch (Exception e) {
isRunning = false;
log.error(Arrays.toString(e.getStackTrace()));
}
}
}에러 핸들링 테스트
애플리케이션 실행 중 에러
애플리케이션 초기화 중 에러
결론
Last updated