2017-02-03 spring-boot-features-custom-failure-analyzer 自定义FailureAnalyzerStep1:自定义异常123456public class BusinessException extends RuntimeException { public BusinessException(String msg){ super(msg); }} Step2:自定义FailureAnalyzer12345678910public class BusinessFailureAnalyzer extends AbstractFailureAnalyzer<BusinessException> { BusinessFailureAnalyzer(){ } @Override protected FailureAnalysis analyze(Throwable throwable, BusinessException e) { return new FailureAnalysis("business description","business action",e); }} Step3:配置FailureAnalyzer12org.springframework.boot.diagnostics.FailureAnalyzer=\org.felix.spring.boot.analyzer.BusinessFailureAnalyzer Step4:定义一个Service被Spring初始化抛出该异常1234567@Componentpublic class EchoService implements InitializingBean{ @Override public void afterPropertiesSet() throws Exception { throw new BusinessException("business exception"); }} Step5:构建一个Spring Application12345678@Configuration@EnableAutoConfiguration@ComponentScanpublic class ApplicationWithBusinessException { public static void main(String[] args) { SpringApplication.run(ApplicationWithBusinessException.class,args); }} Step6:运行Spring Application1234567891011***************************APPLICATION FAILED TO START***************************Description:business descriptionAction:business action Ancien spring-boot-application-starters