Sending Spring mails with AOP

We can also send mails by integrating the mailing functionality with Aspect Oriented Programming (AOP). This can be used to send mails after the user registers with an application. Think of a scenario where the user receives an activation mail after registration. This can also be used to send information about an order placed on an application. Use the following steps to create a MailAdvice class using AOP:

  1. Create a package called com.packt.aop.
  2. Create a class called MailAdvice.
    public class MailAdvice {
      public void advice (final ProceedingJoinPoint proceedingJoinPoint) { new Thread(new Runnable() { public void run() { System.out.println("proceedingJoinPoint:"+proceedingJoinPoint); try { proceedingJoinPoint.proceed(); ...

Get Mastering Spring Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.