package com.storlead.framework.common.config;


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

import javax.annotation.Resource;

/**
 * @program: sp-salary-system
 * @description:
 * @author: chenkq
 * @create: 2024-10-17 09:32
 */
@Component
public class AutowiringSpringBeanJobFactory extends SpringBeanJobFactory {

    @Resource
    private AutowireCapableBeanFactory beanFactory;

    @Override
    protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
        // 使用父类方法创建 Job 实例
        Object jobInstance = super.createJobInstance(bundle);
        // 将 Spring 管理的 Bean 注入到 Job 实例中
        beanFactory.autowireBean(jobInstance);
        return jobInstance;
    }
}

