spring quartz 的定时任务的绑定

spring quartz 的定时任务的绑定
1.bms-servlet.xml
<bean id="createBookmarkReport" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
		<property name="targetObject" ref="analyPv" />
		<property name="targetMethod" value="createBookmarkReport"/>
	</bean>

    <bean id="analyPv" class="com.lenovomobile.wap.scheduler.AnalyPVJob">
		<property name="bms" ref="bms"/>
	</bean>

    <bean id="createBookmarkReportTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
		<property name="jobDetail" ref="createBookmarkReport"/>
		<!--<property name="cronExpression" value="0 15 6 * * ?" />-->
        <property name="cronExpression" value="0 45 15 * * ?" />
    </bean>

    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
		<property name="triggers">
			<list>
				<ref bean="createBookmarkReportTrigger"/>
			</list>
		</property>
	</bean>


2.AnalyPVJob.java

public class AnalyPVJob {

    private BmsFacade bms;

    public void setBms(BmsFacade bms) {
        this.bms = bms;
    }

    Logger logger = Logger.getLogger("Create-Bms Log-Report");

    // 创建跳转链接表
    public void createBookmarkReport() {
        String date = date();
        logger.info("Bms Log Report start,,,");
        try {
            int i = this.bms.existTable("wap_log_" + date);
            if (i == 0) {
                this.bms.createTable(date);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        logger.info("Bms Log Report end,,,");
    }

    private String date() {
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
        return format.format(new Date());
    }

}


3.  0 45 15 * * ?  每天15点45分触发
4. build.xml 文件加载的包

<property name="spring.root" value="c:/spring"/>


	<path id="master-classpath">

		<fileset dir="${spring.root}/lib/ibatis">
			<include name="ibatis-common-2.jar"/>
			<include name="ibatis-sqlmap-2.jar"/>
		</fileset>
		<fileset dir="${spring.root}/lib/j2ee">
			<include name="servlet-api.jar"/>
		</fileset>
		<fileset dir="${spring.root}/lib/jakarta-commons">
			<include name="commons-logging.jar"/>
		</fileset>
		<fileset dir="${spring.root}/dist">
			<include name="spring.jar"/>
		</fileset>
		<fileset dir="${spring.root}/lib/log4j">
			<include name="log4j-1.2.13.jar"/>
		</fileset>
		<fileset dir="${spring.root}/lib/image">
			<include name="Image4J.jar"/>
		</fileset>
        <fileset dir="${spring.root}/lib/jexcelapi">
			<include name="jxl.jar"/>
		</fileset>

    </path>

你可能感兴趣的:(java,spring,xml,quartz,WAP)