FailedAnalyzer 自定义实现

import org.springframework.boot.diagnostics.FailureAnalysis;
import org.springframework.boot.diagnostics.FailureAnalyzer;
/**
 * Created by JavaDeveloperZone on 03-05-2018.
 * Here we have implements FailureAnalyzer and override analyze method which will be
 * called automatically when application startup will get failed.
 */
public class CustomFailedAnalyzer implements FailureAnalyzer {
    @Override
    public FailureAnalysis analyze(Throwable failure) {
        return new FailureAnalysis("Custom Failed Message : ",failure.getMessage(),failure);
    }
}

spring.factories文件配置

org.springframework.boot.diagnostics.FailureAnalyzer=com.javadeveloperzone.CustomFailedAnalyzer

注意:必须放置在resources/META-INF
spring boot之FailureAnalyzer_第1张图片

原文地址:https://javadeveloperzone.com/spring-boot/spring-boot-startup-failure-analyzer-example/