您的位置:首页 > 编程语言 > Java开发

springMVC配置定时器

2017-03-31 22:59 253 查看
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包

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  spring定时器 quartz