不多说废话,直接上代码
Aop拦截代码
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
@Aspect
@Configuration
@Slf4j
public class FilterScheduledAop {
@Value("${scheduled.filter}")
private boolean scheduledFilter;
@Pointcut(" @annotation(org.springframework.scheduling.annotation.Scheduled)")
public void proxyAspect() {
}
@Around("proxyAspect()")
public Object doInvoke(ProceedingJoinPoint joinPoint) {
if (!scheduledFilter) {
try {
return joinPoint.proceed();
} catch (Throwable e) {
log.info("定时拦截器异常", e);
}
}else {
log.info("定时任务已被拦截!!!");
}
return null;
}
}