spring mvc 定时任务

配置文件java

    <bean id="TestController" class="com.whty.mytest.controller.TestController"></bean>
    <bean id="printhahaha" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject" ref="TestController" />
        <property name="targetMethod" value="printhahaha"/>
        <property name="concurrent" value="false" />
    </bean>
    <bean id="printhahahaTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> 
        <property name="jobDetail" ref="printhahaha" /> 
        <!-- 每30秒执行 -->
        <property name="cronExpression" value="0/30 * * * * ?" />
    </bean>
    
    <!-- 触发器工厂,将全部的定时任务都注入工厂-->  
    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <!--  添加触发器   -->
        <property name="triggers">
            <list>
            <ref local="printhahahaTrigger" />
            </list>
        </property>
        <!-- 链接线程池配置文件 -->
        <property name="configLocation" value="classpath:properties/quartz.properties" />
    </bean>

java类spring

package com.whty.mytest.controller;

@Controller
@RequestMapping("/myTest")
public class TestController {
    public void printhahaha(){
        System.out.println("哈哈哈哈哈哈哈哈");
    }
}
相关文章
相关标签/搜索