Don't mask original exception in SpringApplication.handleError

If any @Import (or @Enable*, especially @EnableScheduling) has registered
bean *names* as ApplicationListeners, and the application context wasn't
refreshed fully when it failed, then the listener lookup could fail and
mask the original exception

Fixes gh-253
pull/272/head
Dave Syer 11 years ago
parent a55809959f
commit dac1b53fda

@ -25,6 +25,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.PoolConfig;
@ -46,6 +47,7 @@ import com.lambdaworks.redis.RedisClient;
*/
@Configuration
@ConditionalOnClass({ LettuceConnection.class, RedisOperations.class, RedisClient.class })
@EnableConfigurationProperties
public class RedisAutoConfiguration {
@Configuration

@ -376,8 +376,19 @@ public class SpringApplication {
protected void handleError(ConfigurableApplicationContext context,
ApplicationEventMulticaster multicaster, Throwable ex, String... args) {
multicaster.multicastEvent(new SpringApplicationErrorEvent(this, context, args,
ex));
try {
multicaster.multicastEvent(new SpringApplicationErrorEvent(this, context,
args, ex));
}
catch (Exception e) {
// We don't want to fail here and mask the original exception
if (this.log.isDebugEnabled()) {
this.log.error("Error handling failed", e);
}
else {
this.log.warn("Error handling failed (" + e.getMessage() + ")");
}
}
if (context != null) {
context.close();
}
@ -1004,8 +1015,8 @@ public class SpringApplication {
@Override
protected Collection<ApplicationListener<?>> getApplicationListeners(
ApplicationEvent event) {
List<ApplicationListener<?>> listeners = new ArrayList<ApplicationListener<?>>(
super.getApplicationListeners(event));
List<ApplicationListener<?>> listeners = new ArrayList<ApplicationListener<?>>();
listeners.addAll(super.getApplicationListeners(event));
if (event instanceof SpringApplicationErrorEvent) {
Collections.reverse(listeners);
}

Loading…
Cancel
Save