spring定时问题? 400 报错
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd ">
<!--定义定时执行Service 这个bean中的test()方法-->
<bean id="doJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<!--你要执行的那个方法对应的bean-->
<property name="targetObject">
<ref bean="service" />
</property>
<!--你要执行那个方法,注意方法不能有返回值,参数好像也不能有-->
<property name="targetMethod">
<value>test</value>
</property>
</bean>
<!--触发器的bean的设置,在这里我们设置了我们要触发的jobDetail是哪个。这里我们定义了要触发的jobDetail是searchEngerneTask,即触发器去触发哪个bean..并且我们还定义了触发的时间-->
<bean id="cronTrigger"
class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="doJob" />
</property>
<property name="cronExpression">
<!-- 关键在配置此表达式,时间设置这里表示每天在下午2:00至2:59之间每1分钟触发一次 ,最后也写出了一些,具体可以自己去找资料看 -->
<value>0/5 * * * * ?</value>
</property>
</bean>
<!--管理触发器的总设置,管理我们的触发器列表,可以在bean的list中放置多个触发器。
-->
<bean autowire="no"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="cronTrigger" />
</list>
</property>
</bean>
</beans>
package org.quartz.service;
import org.quartz.dao.Schedule; import org.springframework.beans.factory.annotation.Autowired;
/** * Created by LIANG on 2017/4/19. */ @org.springframework.stereotype.Service("service") public class ServiceImpl implements Service {
@Autowired
private Schedule schedule;
@Override
public void test() {
System.out.println("test...............");
schedule.scheduled();
}
}
为什么不会执行呢????大神们求解答,Tomcat没有出错
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
ref="service" 你还需要一个<bean id ="service" class="xxx.xxx.Service"/>
虽然你在类里加了注解,但你没扫描也没卵用
######回复 @LH_小燕子 : 启动只需要ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:spring-quartz.xml");就行了######<bean id="scr" class="org.quartz.service.Services"></bean> 这里有错的,如果是实现类的话, schedule.scheduled()这个方法不会调用######楼上正解