JobFactory.java 797 Bytes
Newer Older
谢恒's avatar
谢恒 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
package com.hs.admin.factory;

import org.quartz.spi.TriggerFiredBundle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.scheduling.quartz.AdaptableJobFactory;
import org.springframework.stereotype.Component;

/**
 * @author xieheng
 */
@Component
public class JobFactory extends AdaptableJobFactory {
    @Autowired
    AutowireCapableBeanFactory autowireCapableBeanFactory;

    @Override
    protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {

        Object jobInstance = super.createJobInstance(bundle);
        //将任务自动注入到factory
        autowireCapableBeanFactory.autowireBean(jobInstance);
        return jobInstance;
    }
}