0

I have following Custom Annotation.

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Scheduled {
    String cron() default "";
    .....

Implementation class

@Named
public class JobDefination {
@Scheduled(concurrent = false, cron = "0 0/1 * * * ?")
    public void removeHistory(){
            .....
}

The Aspect

@Aspect
@Component
public class AspectImple {
@Before("@annotation(com.quartzConfiguration.Scheduled)")
        public void beforeImplAnnotation() {
              ...
        }
@Before("execution(* com.job.defination.JobDefination.*()) && @annotation(com.quartzConfiguration.Scheduled)")
        public void beforeImpl2() {
            ...
        }

I have tried with above pointcut one by one. But AOP not working when when quartz calling the method. Could someone please help.

abhijit nag
  • 451
  • 6
  • 24
  • Two notes: Spring has a `@Scheduled` annotation. It's definition, not defination. Is your annotated object managed by spring? – Sotirios Delimanolis Jul 26 '13 at 14:01
  • No, this annotated Object is our custom implementation – abhijit nag Jul 26 '13 at 14:10
  • I meant "Does Spring control the lifecycle of the object? Does it create it?" It needs to create a Proxy for it to be advised. – Sotirios Delimanolis Jul 26 '13 at 14:11
  • @Sotirios Delimanolis : Sorry for delayed replied. Log suggests Spring is controlling the life-cycle of this bean and also creating proxy but failing to apply any advised on the method. .. Some log snaps AnnotationAwareAspectJAutoProxyCreator - Creating implicit proxy for bean 'jobDefination' with 0 common interceptors and 5 specif ic interceptors....... Cglib2AopProxy - Unable to apply any optimisations to advised method: public void com.job.defination.JobDefination.removeHistory() – abhijit nag Jul 30 '13 at 08:34

1 Answers1

0

You need to make sure that the quartz jobs are created within the spring context. There is already a question covering that topic here: inject bean reference into a Quartz job in Spring?

Community
  • 1
  • 1
Henrik Sachse
  • 51,228
  • 7
  • 46
  • 59