quartz定时任务框架

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:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="http://www.springframework.org/schema/beans  
                        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd  
                        http://www.springframework.org/schema/context  
                        http://www.springframework.org/schema/context/spring-context-3.1.xsd  
                        http://www.springframework.org/schema/tx
                        http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
                        http://www.springframework.org/schema/mvc  
                        http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
                        http://www.springframework.org/schema/aop 
                        http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">   
	<!-- 注解标签驱动开启 -->
	<mvc:annotation-driven></mvc:annotation-driven>
	<!-- 当在web.xml 中 DispatcherServlet使用 <url-pattern>/</url-pattern> 映射时,能映射静态资源 -->
	<mvc:default-servlet-handler />
	
	<context:annotation-config />
	
	<!-- 静态资源映射 -->
	<mvc:resources location="/WEB-INF/static/**" mapping="/static/**"/>
	
	<!-- 默认的视图解析器 在上边的解析错误时使用 (默认使用html)- -->
	<bean id="defaultViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:order="1">
		<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
		<property name="contentType" value="text/html" />
		<property name="prefix" value="/WEB-INF/jsp/" />
		<property name="suffix" value=".jsp" />
	</bean>
	
	<!--避免IE执行AJAX时,返回JSON出现下载文件 -->
	<bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
		<property name="supportedMediaTypes">
			<list>
				<value>text/html;charset=UTF-8</value>
			</list>
		</property>
	</bean>
	<!-- 启动SpringMVC的注解功能,完成请求和注解POJO的映射 -->
	<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
		<property name="messageConverters">
			<list>
				<ref bean="mappingJacksonHttpMessageConverter" />	<!-- JSON转换器 -->
			</list>
		</property>
	</bean>
	
	<!-- 开启controller注解支持 -->
	<!-- 注意事项请参考:http://jinnianshilongnian.iteye.com/blog/1762632 -->
	<context:component-scan base-package="cn">
	</context:component-scan>
	
	<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
		<!-- 最大下载速度 -->
		<property name="maxUploadSize">
			<value>104857600</value>
		</property>
		<property name="maxInMemorySize">
			<value>2048</value>
		</property>
	</bean>
	<!-- 定时任务框架 -->
	<bean id="quar" class="cn.com.demo.quartz.Quartz"></bean><!-- 定义的类 -->
	<bean id="factoryBeanMethod" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
		<property name="targetObject">
			<ref bean="quar"/>  <span style="font-family: Arial, Helvetica, sans-serif;"><!-- 定义的类引用--></span>

		</property>
		<property name="targetMethod">
			<value>exe</value>  <span style="font-family: Arial, Helvetica, sans-serif;"><!-- 定义的类里执行的方法名 --></span>
		</property>
	</bean>
	<!-- ======================== 调度触发器 ======================== -->  
	<bean id="tigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
		<property name="jobDetail" ref="factoryBeanMethod"></property>
		<property name="cronExpression" value="0/5 * * * * ?"></property>
	</bean>
	<!-- ======================== 调度工厂 ======================== -->
	<bean id="factoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
		<property name="triggers">
			<list>
				<ref bean="tigger"/>
			</list>
		</property>
	</bean> 
</beans>
任务框架类

package cn.com.demo.quartz;

import java.sql.Date;

/**
 * 定时任务类
 * */
public class Quartz
{
	private void exe()
	{
		long str=System.currentTimeMillis();
		System.out.println(new Date(str));
	}
}
web.xml
  <!-- 加载spring容器 -->
  <context-param>
  	<param-name>contextConfigLocation</param-name>
  	<param-value>classpath:spring/spring-context.xml,classpath:spring/spring-mvc.xml</param-value>
  </context-param>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值