From: Gustavo Martin Morcuende Date: Sat, 26 Mar 2016 00:08:51 +0000 (+0100) Subject: Spring emails: when using @Async exceptions are caught by SimpleAsyncUncaughtExceptio... X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=7e6e235e0ad650daaa3d8fdfd416a6ed4f76207a;p=JavaForFun Spring emails: when using @Async exceptions are caught by SimpleAsyncUncaughtExceptionHandler --- 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" />