0

I created a custom class level annotation.

Below is the aspect class:

@Aspect
@Slf4j
@Component
public class LoggingAspect {
    private String generateLogMessage() {
        return ("Entering method");
    }

    @Before("@within(mypackage.logging.Loggable) || @annotation(mypackage.logging.Loggable)")
    public void logMethodEntry(JoinPoint joinPoint) {
        String logMessage = generateLogMessage();
        log.debug(logMessage);
    }
} 

Below is my custom annotation:

@Target(value = {ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Loggable { }

When I use the annotation at class level it works. But if I am calling different methods within the same class the logging is done only once. I want to do the logging for each methods called using the class level @Loggable annotation.

I tried to use it at method level it works. But I want to use it at class level.

kriegaex
  • 63,017
  • 15
  • 111
  • 202
  • 2
    Without checking the complete code with the issue , based on the problem statement, a wild guess is that the issue is self invocation . Do read through the [documenation](https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#aop-pointcuts-designators) , Notes section – R.G Jan 31 '23 at 11:15
  • 1
    starting with "Due to the proxy-based nature of Spring’s AOP framework, .." – R.G Jan 31 '23 at 11:15
  • Please learn [how to ask a question on SO](https://stackoverflow.com/help/how-to-ask) and provide a [minimal, complete, and verifiable example](https://stackoverflow.com/help/mcve). Thank you. Specifically for AOP, it makes sense to not just show the aspect but also the code it targets. Otherwise, the picture is incomplete. It is hard to reason about an aspect out of context. – kriegaex Feb 04 '23 at 09:18

0 Answers0