朱杰兵blog

jonhney'blog
posts - 140, comments - 1, trackbacks - 0, articles - 0

spring定时器的配置

Posted on 2013-02-27 20:57 朱杰兵 阅读(840) 评论(0)  编辑  收藏
1>需要的jar包 quartz-all-1.5.2.jar
2>添加application-job.xml
<!--    注入service-->
    <bean id="quarzJob" class="com.wonders.sjyy.job.QuarzJob">
        <property name="appointmentService" ref="appointmentService" />
    </bean>
    
    <!-- 定时任务的配置 -->
    <bean id="jobDetailBean1"
        class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject" ref="quarzJob" />
        <property name="targetMethod" value="sctingzhen" />
    </bean>
    <bean id="jobDetailBean2"
        class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject" ref="quarzJob" />
        <property name="targetMethod" value="scYishengScheduling" />
    </bean>
    
    <!---->
    <bean id="triggerBean1"
        class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="jobDetailBean1" />
        <property name="cronExpression" value="0 0/5 * * * ?" />
    </bean>
    <bean id="triggerBean2"
        class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="jobDetailBean2" />
        <property name="cronExpression" value="0 0/5 * * * ?" />
    </bean>
    
    <bean id="schedulerFactoryBean"
        class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
                <ref bean="triggerBean1" />
                <ref bean="triggerBean2"/>
            </list>
        </property>
    </bean>

3>定时任务方法编写
package com.wonders.sjyy.job;

import java.net.MalformedURLException;
import java.net.URL;

import org.codehaus.xfire.client.Client;

import com.wonders.sjyy.service.DoctorAppointmentService;

public class QuarzJob {
    
    
    private DoctorAppointmentService appointmentService;

    /**
     * 抽取ee信息
     * @return
     */
    public String sctingzhen(){
        /*String reString="";
        try {
            Client client = new Client(new URL("http://172.16.254.202:8089/xhws_znts_lhyy/services/ISjyyService?wsdl"));
            client.setTimeout(0);
            Object[] results = client.invoke("LHS204",
                    new Object[] { "","" });
            reString=(String)results[0];
            System.out.println(reString.length());
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return reString;*/
        
        System.out.println("抽取ee信息");
        return null;
    }
    
    /**
     * 抽取xx信息
     * @return
     */
    public String scYishengScheduling(){
        /*String reString="";
        try {
            Client client = new Client(new URL("http://172.16.254.202:8089/xhws_znts_lhyy/services/ISjyyService?wsdl"));
            client.setTimeout(0);
            Object[] results = client.invoke("LHS203",
                    new Object[] { "","" });
            reString=(String)results[0];
            System.out.println("接受--->"+reString);
            System.out.println(reString.length());
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return reString;*/
        
        System.out.println("上传xx信息");
        return null;
    }
    public DoctorAppointmentService getAppointmentService() {
        return appointmentService;
    }

    public void setAppointmentService(DoctorAppointmentService appointmentService) {
        this.appointmentService = appointmentService;
    }

}

只有注册用户登录后才能发表评论。


网站导航:
博客园   IT新闻   Chat2DB   C++博客   博问