Question Description

  1. Custom Annoation
@Retention(RUNTIME)  
@Target(METHOD)
public @interface AspectTest {
}
  1. Defining Inteface Class and Implement Class
public interface AnnotationInterface {
    @AspectTest
    void print();
}

@Component
public class ExampleTwoBean implements AnnotationInterface {
    private static final Logger log = LoggerFactory.getLogger(ExampleTwoBean.class);

    @Override
    public void print() {
        log.info("ExampleTwoBean: print method");
    }
}

  1. Defining Aspect
@Aspect
@Component
public class AnnotationAspect {
    private static final Logger log = LoggerFactory.getLogger(AnnotationAspect.class);
    @Pointcut("@annotation(package.AspectTest)")
    public void withinMethod() {
        // Do nothing because of just define pointcut
    }

    @Around("withinMethod()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        log.info("Annotation:  start.");
        Object retVal = pjp.proceed();
        log.info("Annotation:  end.");
        return retVal;
    }
}
  1. Run the SpringBoot Application。 When we invocation the ExampleTwoBean#print function, the poincut not working。

Expected Result

The log contain: "Annotation: start." and "Annotation: end."

Acutally Result

The log not contain: "Annotation: start." and "Annotation: end."

Comment From: wilkinsona

Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.

If you do post on Stack Overflow, anyone trying to help you will need some more information. As you've opened an issue here, I assume you're using Spring Boot, but that's not clear from the code you've shared. The dependencies that you're using and their versions are also absent.