上图为任务代码,在任务具体执行的方法中使用,一定要写在方法内使用
SpringContextUtil.getBean()方法实例化Spring service类
下边是ruoyi-quartz模块中util/SpringContextUtil.java(已改写)
import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.stereotype.Service; /** * spring管理环境中获取bean * * @author yangzz */ @Service("springContextUtil") public class SpringContextUtil implements ApplicationContextAware { // Spring应用上下文环境 private static ApplicationContext applicationContext; /** * 实现ApplicationContextAware接口的回调方法,设置上下文环境 * * @param applicationContext