mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
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
This commit is contained in:
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…
Reference in New Issue
Block a user