I've got this EnableArgumentLogging class
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface EnableArgumentLogging {
}
I would like to use it in my other class, called LoggingAspect
@Aspect
@Component
public class LoggingAspect {
private static final Logger LOGGER = LoggerFactory.getLogger(LoggingAspect.class);
@Before("@annotation(EnableArgumentLogging)")
public void logArguments(JoinPoint joinPoint) {
StringBuilder argumentString = new StringBuilder();
Arrays.stream(joinPoint.getArgs()).forEach(o -> argumentString.append(o.toString()));
LOGGER.info("Method name : [" + joinPoint.getSignature().getName() + "], parameter(s): [" + argumentString + "]");
}
}
In this case I got an error: Cannot resolve symbol 'EnableArgumentLogging'
What did I miss to add here?
@annotation()
accepts fully qualified name of the annotation, that is class name with package.
Example:
@Before("@annotation(com.example.annotations.EnableArgumentLogging)")