I'm writing an aspect to log Request and Response of each API call in a controller. I want to be able to use this annotation on a class, hence used @Target(ElementType.TYPE)
Previously I had added @Target(ElementType.Method) and I was using this annotation on methods and it was working fine. Now I want to change it to @Target(ElementType.TYPE)
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface ReLogger {}
@Aspect
@Component
public class ReLoggerAspect {
public static final Logger log = LoggerFactory.getLogger("ReLoggerAspect");
@PostConstruct
private void postConstruct() {
log.info("ReLoggerAspect Created");
}
@Around("@annotation(ReLogger)")
private Object reqLoggingAspect(ProceedingJoinPoint joinPoint) throws Throwable {
log.info("Request {}",jointPoint.getArgs()[0);
}
}
Using @ReLoggerAspect on a class
@RestController
@RequestMapping(value = "....", produces = { "application/json" })
@ReLogger
public class Samplecontroller {
/** Some logic here**/.....
}
It doesn't print the Request when an API SampleController is invoked