Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package ru.stoloto.contacts.aop; import lombok.extern.log4j.Log4j2; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; import org.springframework.beans.factory.annotation.Autowired; import ru.stoloto.contacts.mail.EmailService; import ru.stoloto.contacts.service.SecurityService; @Log4j2 @Aspect public class LoggingUserOperationsAspect { @Autowired EmailService emailService; @Autowired SecurityService securityService; @Pointcut("execution(* ru.stoloto.contacts.service.*.*(..)) " + "&& within(ru.stoloto.contacts.services..*)" + "&& @annotation(ru.stoloto.contacts.aop.Logging)") public void authLogExecution() { } @Pointcut("execution(* ru.stoloto.contacts.controllers.*.*(..)) " + "&& within(ru.stoloto.contacts.controllers..*)" + "&& @annotation(ru.stoloto.contacts.aop.Logging)") public void authLogControllerExecution() { } @Pointcut("execution(* ru.stoloto.contacts.controllers.*.*(..)) " + "&& within(ru.stoloto.contacts.controllers..*)" + "&& @annotation(ru.stoloto.contacts.aop.MailNotify)") public void mailNotify() { } @Before("mailNotify()") public void mailNotify(JoinPoint joinPoint) { // User currentUser = securityService.getCurrentUser(); // // emailService.sendAsync("igory.kapralov@stoloto.ru", currentUser.getEmail(), joinPoint.getSignature().toShortString(), // "You are doing " + joinPoint.toLongString()); } @Around("authLogExecution()") public Object authLogExecution(ProceedingJoinPoint joinPoint) throws Throwable { log.info(joinPoint.toString()); Object object = joinPoint.proceed(); return object; } @Around("authLogControllerExecution()") public Object authLogControllerExecution(ProceedingJoinPoint joinPoint) throws Throwable { log.info(joinPoint.toString()); Object object = joinPoint.proceed(); return object; } }