The pointcut pointer you are looking for can be listed below:
@Aspect public class SomeClass { @Around("@annotation(org.springframework.scheduling.annotation.Scheduled)") public void doIt(ProceedingJoinPoint pjp) throws Throwable { System.out.println("before"); pjp.proceed(); System.out.println("After"); } }
I'm not sure if all you need or not. Therefore, I will also post other parts of the solution.
First of all, pay attention to the @Aspect annotation in the class. The methods of this class are required to be used as advice .
In addition, you must ensure that the class that the @Scheduled method @Scheduled is detected by scanning. You can do this by annotating this class with @Component annotation. For example:
@Component public class OtherClass { @Scheduled(fixedDelay = 5000) public void doSomething() { System.out.println("Scheduled Execution"); } }
Now, for this to work, the required parts in your spring configuration would be the following:
<context:component-scan base-package="com.example.mvc" /> <aop:aspectj-autoproxy /> <task:annotation-driven />
source share