DEV Community

Discussion on: Spring Boot Debugging with Aspect-Oriented Programming (AOP)

Collapse
 
codenameone profile image
Shai Almog

Yes, I should have demonstrated that. I recommended using them for performance but didn't include it as a sample.

For reference we can do something like this:

public class DebugCondition implements Condition {
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        // Check if a "debug" profile is active
        return context.getEnvironment().acceptsProfiles("debug");
    }
}
Enter fullscreen mode Exit fullscreen mode

We can then do:

@Aspect
@Component
@Conditional(DebugCondition.class)
public class LoggingAspect {
   //...
}
Enter fullscreen mode Exit fullscreen mode

Which will show the aspect only in debug mode.