i want have aspectj pointcut methods annotated @scheduled
. tried different approaches nothing worked.
1.)
@pointcut("execution(@org.springframework.scheduling.annotation.scheduled * * (..))") public void scheduledjobs() {} @around("scheduledjobs()") public object profilescheduledjobs(proceedingjoinpoint joinpoint) throws throwable { log.info("testing") }
2.)
@pointcut("within(@org.springframework.scheduling.annotation.scheduled *)") public void scheduledjobs() {} @pointcut("execution(public * *(..))") public void publicmethod() {} @around("scheduledjobs() && publicmethod()") public object profilescheduledjobs(proceedingjoinpoint joinpoint) throws throwable { log.info("testing") }
can suggest other way have around
/before
advice on @scheduled
annotated methods?
the pointcut looking can specified 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 not sure whether that's require or not. i'm going post other parts of solution well.
first of all, notice @aspect
annotation on class. required methods in class applied advice
.
also, need make sure class has @scheduled
method detectable via scanning. can annotation class @component
annotation. ex:
@component public class otherclass { @scheduled(fixeddelay = 5000) public void dosomething() { system.out.println("scheduled execution"); } }
now, work, required parts in spring configuration follows:
<context:component-scan base-package="com.example.mvc" /> <aop:aspectj-autoproxy /> <!-- @aspect work --> <task:annotation-driven /> <!-- @scheduled work -->
Comments
Post a Comment