springMVC配置定时器

来源:互联网 发布:phpmyadmin linux 安装 编辑:程序博客网 时间:2024/06/14 07:11

1.web.xml文件中包含代码片:

 <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:config/applicationContext.xml,classpath*:config/spring-context-job.xml  </param-value>
    </context-param>

2.在spring-context-job.xml中写进

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc"  
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd"
    default-lazy-init="false">

    <beans>
        <bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
            <property name="triggers">
                <list>
                   <ref local="weixinServiceTrigger"/>
                </list>
            </property>
        </bean>

        
        <bean id="weixinServiceTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">
            <property name="jobDetail" ref="weixinServiceDetail"/>
            <property name="startDelay" value="0" />  
            <property name="repeatInterval" value="500" />
        </bean>
        <bean id="userService" class="com.JunitTest1"></bean>
        <bean id="weixinServiceDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
            <property name="targetObject" ref="userService"/>
            <property name="targetMethod" value="sys"/>
            <property name="concurrent" value="false"/>
        </bean>
    </beans>
</beans>

3,写需要定时启动的方法

4,传五个jar包


0 0
原创粉丝点击