From 7e6e235e0ad650daaa3d8fdfd416a6ed4f76207a Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Sat, 26 Mar 2016 01:08:51 +0100 Subject: [PATCH] Spring emails: when using @Async exceptions are caught by SimpleAsyncUncaughtExceptionHandler --- .../java/de/spring/webservices/rest/controller/EmailController.java | 3 +++ .../src/main/resources/spring-configuration/spring-configuration.xml | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/SpringJava/Emails/spring-emails-web-client/src/main/java/de/spring/webservices/rest/controller/EmailController.java b/SpringJava/Emails/spring-emails-web-client/src/main/java/de/spring/webservices/rest/controller/EmailController.java index 583e66a..56e98f4 100644 --- a/SpringJava/Emails/spring-emails-web-client/src/main/java/de/spring/webservices/rest/controller/EmailController.java +++ b/SpringJava/Emails/spring-emails-web-client/src/main/java/de/spring/webservices/rest/controller/EmailController.java @@ -54,6 +54,9 @@ public class EmailController { try { emailService.sendEmailAsync(to, emailSubject, emailText, true, null, inline); } catch (MessagingException ex) { + // WARNING!!!! + // Because we are using @Async we will never catch thrown exceptions from sendEmailAsync. + // Exceptions will be caught by org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler. :( LOGGER.error("Send email error", ex); } } diff --git a/SpringJava/Emails/spring-emails-web-client/src/main/resources/spring-configuration/spring-configuration.xml b/SpringJava/Emails/spring-emails-web-client/src/main/resources/spring-configuration/spring-configuration.xml index 4589e60..e12ef32 100644 --- a/SpringJava/Emails/spring-emails-web-client/src/main/resources/spring-configuration/spring-configuration.xml +++ b/SpringJava/Emails/spring-emails-web-client/src/main/resources/spring-configuration/spring-configuration.xml @@ -24,7 +24,7 @@ + queue-capacity="0" rejection-policy="CALLER_RUNS" /> -- 2.1.4