spring boot devtools 를 사용 합 니 다.

spring-boot-devtools 는 좋 은 것 입 니 다.디 버 깅 을 개발 할 때 수시로 열 배 치 를 할 수 있 고 매번 손 으로 시작 하지 않 아 도 됩 니 다.이틀 전 한 항목 에서 log 를 찾 았 는데,항상 이러한 오류 로그 출력 이 있 음 을 발 견 했 습 니 다.
org.springframework.boot.devtools.restart.SilentExitExceptionHandler$SilentExitException  at org.springframework.boot.devtools.restart.SilentExitExceptionHandler.exitCurrentThread(SilentExitExceptionHandler.java:90)  at org.springframework.boot.devtools.restart.Restarter.immediateRestart(Restarter.java:184)  at org.springframework.boot.devtools.restart.Restarter.initialize(Restarter.java:163)  at org.springframework.boot.devtools.restart.Restarter.initialize(Restarter.java:552)  at org.springframework.boot.devtools.restart.RestartApplicationListener.onApplicationStartingEvent(RestartApplicationListener.java:67)  at org.springframework.boot.devtools.restart.RestartApplicationListener.onApplicationEvent(RestartApplicationListener.java:45)  at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167)  at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)  at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)  at org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:68)  at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:48)  at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)  at org.test.Application.main(Application.java:15)
프로젝트 의 주체 구 조 를 살 펴 보 자.대체적으로 이렇다.나 는 간소화 했다.
우선 spring boot 의 시작 입구 입 니 다:
package org.test;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.Banner.Mode;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        try {
            SpringApplication app = new SpringApplication(Application.class);
            app.setBannerMode(Mode.OFF);
            app.setWebEnvironment(false);
            app.run(args);
        }
        catch(Exception ex) {
            ex.printStackTrace();
        }
    }
}

주 서 비 스 는 대체로 다음 과 같다.
package org.test;

import javax.annotation.PostConstruct;
import org.springframework.stereotype.Service;

@Service
public class MainService {
    @PostConstruct
    public void startServer() {
        System.out.println("START");
    }
}

시작 하기 만 하면 위의 오 류 를 보고 하지만 실제 적 으로 어떠한 기능 에 도 영향 을 주지 않 고 devtools 의 열 배치 기능 도 여전히 유효 합 니 다.이전 항목 을 비교 해 보 니 main()방법 에 문제 가 있 습 니 다.SpringApplication.run()은 try..catch 블록 에 넣 으 면 devtools 가 이상 하 게 던 집 니 다.main()에 있 는 try..catch 를 제거 하거나 app.run(args)이라는 문장 을 try..catch 로 옮 기거 나 catch 가 이상 할 때 printStackTrace()를 사용 하지 않 고 실행 하면 오류 로그 가 없습니다.
구체 적 인 원인 은 시간 이 나 면 원본 코드 를 뒤 져 보 세 요.spring boot 에 있어 서 시작 할 때 try..catch 는 정말 쓸데없는 짓 입 니 다.

좋은 웹페이지 즐겨찾기