Quartz 의 Job 은 Spring 이 주입 한 Bean 을 사용 합 니 다.

1134 단어 Java
import org.quartz.spi.TriggerFiredBundle;  
import org.springframework.beans.BeansException;  
import org.springframework.context.ApplicationContext;  
import org.springframework.context.ApplicationContextAware;  
import org.springframework.scheduling.quartz.SpringBeanJobFactory;  
  
public class JobBeanJobFactory extends SpringBeanJobFactory implements ApplicationContextAware {  
      
    private ApplicationContext applicationContext;  
  
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {  
        this.applicationContext = applicationContext;  
    }  
  
    @Override  
    protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {  
        Object jobInstance = super.createJobInstance(bundle);  
        // Job  Spring   ,  Job     Spring   Bean   
        applicationContext.getAutowireCapableBeanFactory().autowireBean(jobInstance);  
        return jobInstance;  
    }  
  
  
}

클래스 를 Scheduler Factory Bean 에 직접 주입 하여 job Factory 속성 에 주입 하면 됩 니 다.
참고:http://blog.csdn.net/a67474506/article/details/38402059

좋은 웹페이지 즐겨찾기