ApplicationEventMulticaster UncaughtExceptionHandler
Я использую SpringEventMulticaster.
Как настроить обработку необработанных ошибок при прослушивании событий?
public ApplicationEventMulticaster asyncApplicationEventMulticaster() {
SimpleApplicationEventMulticaster eventMulticaster = new
SimpleApplicationEventMulticaster();
eventMulticaster.setTaskExecutor(getAsyncExecutor());
return eventMulticaster;
}
1 ответ
Заверните исполнителя:
public class LoggingExecutor implements Executor {
private static final Logger logger = LoggerFactory.getLogger(LoggingExecutor.class);
private Executor executor;
public LoggingExecutor(Executor executor) {
this.executor = executor;
}
@Override
public void execute(Runnable task) {
Runnable runnable=new Runnable() {
@Override
public void run() {
try {
task.run();
} catch (Exception e) {
logger.error("Uncaught exception", e);
throw e;
}
}
};
executor.execute(task);
}}