quartz定时任务框架

来源:互联网 发布:搞笑淘宝买家丝袜秀 编辑:程序博客网 时间:2024/04/30 00:46

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>



0 0
原创粉丝点击