Monday, February 8, 2021

Getting Objects in Aspects

 import lombok.extern.slf4j.Slf4j;

import org.aspectj.lang.annotation.After;

import org.aspectj.lang.annotation.Aspect;

import org.springframework.stereotype.Component;

/**

 * Aspect to log the message when object is saved

 */

@Slf4j

@Aspect

@Component

public class MyLoggerAspect {

// "obj" is object_which_is_saved_in_save_method i.e in com.foo.save(*)

@After("execution(* com.foo.save(*)) && args(obj)")

public void logAfterSavingTheObject(CustomObject obj) {

log.info("Logging after the CustomObject is saved, id : {}", obj.getId())

}

}

1 comment:

  1. https://wkrzywiec.medium.com/moving-into-next-level-in-user-log-events-with-spring-aop-3b4435892f16#e9cf

    ReplyDelete