I'm working on AOP for the first time. It's not working - Maybe I'm mixing up Spring AOP and AspectJ, I'm not sure.
dependency declaration in Gradle file
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
...
compile("org.aspectj:aspectjweaver:1.8.9")
}
}
Configuration class
@Configuration
@EnableAspectJAutoProxy
public class AspectJConfiguration{
@Bean
public MailQueueServiceAspect mailQueueServiceAspect(){
return new MailQueueServiceAspect();
}
}
Aspect Class
@Aspect
public class MailQueueServiceAspect {
private final Logger log = LoggerFactory.getLogger(MailQueueServiceAspect.class);
@Pointcut("execution(* com.biscom.bsend.core.SaveMailHelper.aopTest())")
private void mailUpdatePointCut(){}
@After("mailUpdatePointCut()")
public void afterSampleCreation(JoinPoint joinPoint) {
log.info("Mail Queue updated successfully.");
}
}
Joint-Point holder class
public class SaveMailHelper extends AbstractHelper<SaveMailInput, SaveMailOutput> {
@Inject
private MailQueueService mailQueueService;
private final Logger log = LoggerFactory.getLogger(SaveMailHelper.class);
@Override
protected void executeHelper(SaveMailInput input, SaveMailOutput output) throws AbstractException {
MailQueue mailQueue = mailQueueService.get(input.getId(), new MailQueue());
BlockExecutor e = new BlockExecutor();
e.execute(input.getMailFrom().shouldSet(mailQueue.isNew(), mailQueue.getMailFrom()), () ->{
mailQueue.setMailFrom(input.getMailFrom().get());
});
output.setEntity(mailQueue);
aopTest();
}
public void aopTest(){
log.info("AOPTest method called.");
}
}
I also tried avoiding Configuration class by placing @Component annotation over Aspect class.