Spring整合quartz遇到的问题
任务里的service无法依赖注入解决方案:
- 第一步:自己写一个类,写上需要执行的任务的代码(不用实现quartz的Job接口)
@Component
public class MyJob {
@Autowired
UserBz userBz;
public void test(){
System.out.println("hahahahahhahahahahhahahahah11111");
System.out.println(userBz);
}
}
- 第二步:修改配置
<!-- 1:定义任务的bean ,这里使用MethodInvokingJobDetailFactoryBean-->
<bean name="lxJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref bean="myJob"/><!-- 指定是哪个定时任务类 -->
</property>
<property name="targetMethod">
<value>test</value><!-- 指定要执行的类里面的哪个方法 -->
</property>
</bean>
<!--其余配置相同-->