001/* 002 * Copyright 2012-2017 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.boot.context.event; 018 019import org.springframework.boot.SpringApplication; 020import org.springframework.context.ConfigurableApplicationContext; 021 022/** 023 * Event published by a {@link SpringApplication} when it fails to start. 024 * 025 * @author Dave Syer 026 * @see ApplicationReadyEvent 027 */ 028@SuppressWarnings("serial") 029public class ApplicationFailedEvent extends SpringApplicationEvent { 030 031 private final ConfigurableApplicationContext context; 032 033 private final Throwable exception; 034 035 /** 036 * Create a new {@link ApplicationFailedEvent} instance. 037 * @param application the current application 038 * @param args the arguments the application was running with 039 * @param context the context that was being created (maybe null) 040 * @param exception the exception that caused the error 041 */ 042 public ApplicationFailedEvent(SpringApplication application, String[] args, 043 ConfigurableApplicationContext context, Throwable exception) { 044 super(application, args); 045 this.context = context; 046 this.exception = exception; 047 } 048 049 /** 050 * Return the application context. 051 * @return the context 052 */ 053 public ConfigurableApplicationContext getApplicationContext() { 054 return this.context; 055 } 056 057 /** 058 * Return the exception that caused the failure. 059 * @return the exception 060 */ 061 public Throwable getException() { 062 return this.exception; 063 } 064 065}