springConfig配置文件:

<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<!-- 配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory"
ref="entityManagerFactory" />
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 启用支持Annotation注解方式的事务管理 -->
<tx:annotation-driven transaction-manager="transactionManager" />
<!-- 把标记了@Controller等注解的类转换为bean -->
<context:component-scan base-package="com.qdshop" /> <!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> -->
<!--文件上传设置-->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize">
<value>10485760</value><!-- 文件上传最大为10M -->
</property>
<property name="maxInMemorySize" value="4096" />
</bean>
<!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 -->
<bean id="velocityCongfig"
class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
<property name="resourceLoaderPath">
<value>/</value>
</property>
<property name="velocityProperties">
<props>
<prop key="input.encoding">UTF-8</prop>
<prop key="output.encoding ">UTF-8</prop>
</props>
</property>
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.velocity.VelocityView" />
<property name="contentType">
<value>text/html;charset=UTF-8</value>
</property>
</bean>
<!-- property-placeholder是一个属性遍历器,定位一个属性文件,属性文件存放的是jdbc一些连接数据 -->
<context:property-placeholder location="classpath:jdbc.properties" />
<!--配置velocity engine默认路径-->
<bean id="velocityEngine"
class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
<property name="resourceLoaderPath" value="/velocity/"></property>
</bean>
<!-- 配置数据源 -->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${driverClassName}" />
<property name="url" value="${url}" />
<property name="username" value="${username}" />
<property name="password" value="${password}" />
<property name="initialSize" value="${initialSize}" />
<property name="maxActive" value="${maxActive}" />
<property name="maxIdle" value="${maxIdle}" />
<property name="minIdle" value="${minIdle}" />
</bean>
<bean name="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceXmlLocation"
value="classpath:persistence.xml" />
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="MYSQL" />
<property name="showSql" value="true" />
<property name="generateDdl" value="false" />
</bean>
</property>
<property name="jpaProperties">
<props>
<!-- 自定义方言 -->
<prop key="hibernate.dialect">
com.qdshop.core.dialect.SystemMySQL5Dialect
</prop>
<!-- 二级缓存配置 -->
<prop key="hibernate.cache.provider_class">
net.sf.ehcache.hibernate.SingletonEhCacheProvider
</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.use_second_level_cache">
true
</prop>
<prop key="hibernate.use_sql_comments">false</prop>
<prop key="hibernate.format_sql">false</prop>
<prop key="hibernate.generate_statistics">true</prop>
</props>
</property>
</bean>
<!-- 定义了与实体相关的dao -->
<bean id="genericEntityDao"
class="com.qdshop.core.base.GenericEntityDao" scope="prototype"
lazy-init="true">
<property name="entityManagerFactory"
ref="entityManagerFactory" />
</bean>
<!--使用泛型DAO作为抽象基类 abstract="true" -->
<bean id="genericDAO" class="com.qdshop.core.base.GenericDAO"
abstract="true" depends-on="genericEntityDao">
<property name="geDao">
<ref bean="genericEntityDao" />
</property>
</bean>
<!-- 系统调度控制器 -->
<bean id="statTask"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<!-- 调用的类 -->
<property name="targetObject" ref="shop_stat" />
<!-- 调用类中的方法 -->
<property name="targetMethod" value="execute" />
<property name="concurrent" value="false" />
</bean>
<bean id="stat_cronTrigger"
class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="statTask" />
<property name="cronExpression" value="0 */30 * * * ?" />
</bean>
<bean id="jobTask"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<!-- 调用的类 -->
<property name="targetObject" ref="shop_job" />
<!-- 调用类中的方法 -->
<property name="targetMethod" value="execute" />
<property name="concurrent" value="false" />
</bean>
<bean id="job_cronTrigger"
class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="jobTask" />
<property name="cronExpression" value="1 0 0 * * ?" />
</bean>
<bean id="orderJobTask"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<!-- 调用的类 -->
<property name="targetObject" ref="order_job" />
<!-- 调用类中的方法 -->
<property name="targetMethod" value="execute" />
<property name="concurrent" value="false" />
</bean>
<bean id="orderJob_cronTrigger"
class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="orderJobTask" />
<property name="cronExpression" value="0/10 * * * * ?" />
</bean>
<bean id="schdulerFactory" lazy-init="false"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="stat_cronTrigger" />
<ref bean="job_cronTrigger" />
<ref bean="orderJob_cronTrigger" />
</list>
</property>
</bean>
<bean id="sensitiveWordInitUtil" class ="com.qdshop.sensitive.util.SensitiveWordInitUtil" scope="singleton" init-method="initKeyWord">
<property name="xmlFile">
<value>classpath:sensitive-word.xml</value>
</property>
</bean>
<!-- Loads MongoDB configuraton -->
<import resource="mongo-config.xml"/>
</beans>

定时执行类

package com.qdshop.manage.timer;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set; import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.apache.zookeeper.Op.Delete;
import org.hibernate.annotations.Where;
import org.hibernate.sql.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import com.qdshop.core.tools.CommUtil;
import com.qdshop.foundation.domain.ApplyRefund;
import com.qdshop.foundation.domain.Complaint;
import com.qdshop.foundation.domain.Evaluate;
import com.qdshop.foundation.domain.OrderForm;
import com.qdshop.foundation.domain.OrderFormLogBean;
import com.qdshop.foundation.domain.Quartz;
import com.qdshop.foundation.domain.User;
import com.qdshop.foundation.service.IApplyRefundService;
import com.qdshop.foundation.service.IComplaintService;
import com.qdshop.foundation.service.IEvaluateService;
import com.qdshop.foundation.service.IOrderFormLogService;
import com.qdshop.foundation.service.IOrderFormService;
import com.qdshop.foundation.service.IQuartzService;
import com.qdshop.foundation.service.ISysConfigService;
import com.qdshop.foundation.service.ITemplateService;
import com.qdshop.foundation.service.IUserService;
import com.qdshop.manage.admin.tools.MsgTools;
import com.sun.org.apache.xpath.internal.operations.And; /**
* @ClassName: OrderJobManageAction
* @Description: 订单相关定时任务
* @author
* @date 2016-5-7 下午5:45:43
*
*/
@SuppressWarnings({"rawtypes","unchecked","unused"})
@Component("order_job")
public class OrderJobManageAction {
@Autowired
private ISysConfigService configService; //投诉接口
@Autowired
private IComplaintService complaintService; @Autowired
private MsgTools msgTools; public void execute() throws Exception{
Calendar cal = null;
Map params = new HashMap();
List<Quartz> quartzs=new ArrayList<Quartz>();
List<ApplyRefund> applyRefunds=new ArrayList<ApplyRefund>();
/**订单超过X天未付款,自动取消**/
int auto_order_cancel = this.configService.getSysConfig().getAuto_order_cancel();
cal = Calendar.getInstance();
params.clear();
cal.add(6, -auto_order_cancel);
params.put("order_time", cal.getTime());
params.put("order_status", Integer.valueOf(1));//未付款
List<OrderForm> cancel_ofs = this.orderFormService
.query("select obj from OrderForm obj where obj.order_time<=:order_time and obj.order_status=:order_status", params, -1, -1);
for (OrderForm of : cancel_ofs){
//订单取消
of.setOrder_status(10);
this.orderFormService.update(of);
} } /**
*
* 功能描述:根据传入name,查询出value值
* 创建人:
* 创建日期:2016年7月28日
* @param name
* @return
*/
private List<Quartz> getQuartzList(String name){
Map map = new HashMap();
map.put("name", name);//取确认订单值
List<Quartz> quartzs=this.quartzService.query("select obj from Quartz obj where obj.name=:name", map, -1, -1);
return quartzs;
} }

spring + quartz 定时的更多相关文章

  1. Spring Quartz定时调度任务配置

    applicationContext-quartz.xml定时调度任务启动代码: <?xml version="1.0" encoding="UTF-8" ...

  2. Spring—Quartz定时调度CronTrigger时间配置格式的实例

    格式说明:[秒] [分] [小时] [日] [月] [周] [年] 序号 说明 是否必填 允许填写的值 允许的通配符 1 秒 是 0-59 , - * / 2 分 是 0-59 , - * / 3 小 ...

  3. Spring—Quartz定时调度CronTrigger时间配置格式说明与实例

    1 .CronTrigger时间格式配置说明 CronTrigger配置格式: 格式: [秒] [分] [小时] [日] [月] [周] [年] 序号 说明 是否必填 允许填写的值 允许的通配符 1 ...

  4. Quartz结合SPRING多任务定时调用

    定义两个被调度的类 public class QuartzJob { public void work() { System.out.println(Spring Quartz的任务调度1被调用!&q ...

  5. spring利用javamail,quartz定时发送邮件 <转>

    原文地址:spring利用javamail,quartz定时发送邮件 <转>作者:物是人非 spring提供的定时发送邮件功能,下面是一个简单的例子以供大家参考,首先从spring配置文件 ...

  6. Spring+quartz集群配置,Spring定时任务集群,quartz定时任务集群

    Spring+quartz集群配置,Spring定时任务集群,quartz定时任务集群 >>>>>>>>>>>>>> ...

  7. java Quartz定时器任务与Spring task定时的几种实现,

    java Quartz定时器任务与Spring task定时的几种实现 基于java 的定时任务实现, Quartz 时间详细配置    请查阅   http://www.cnblogs.com/si ...

  8. Spring+Quartz集群环境下定时调度的解决方案

    集群环境可能出现的问题 在上一篇博客我们介绍了如何在自己的项目中从无到有的添加了Quartz定时调度引擎,其实就是一个Quartz 和Spring的整合过程,很容易实现,但是我们现在企业中项目通常都是 ...

  9. Spring整合quartz2.2.3总结,quartz动态定时任务,Quartz定时任务集群配置

    Spring整合quartz2.2.3总结,quartz动态定时任务,Quartz定时任务集群配置 >>>>>>>>>>>>&g ...

随机推荐

  1. iOS 9应用开发教程之ios9中实现button的响应

    iOS 9应用开发教程之ios9中实现button的响应 IOS9实现button的响应 button主要是实现用户交互的.即实现响应.button实现响应的方式能够依据加入button的不同分为两种 ...

  2. Lintcode---线段树构造||

    线段树是一棵二叉树,他的每个节点包含了两个额外的属性start和end用于表示该节点所代表的区间.start和end都是整数,并按照如下的方式赋值: 根节点的 start 和 end 由 build  ...

  3. Exif.js获取图片的详细信息(苹果手机移动端上传图片旋转90度)

    Exif.js插件介绍 http://code.ciaoca.com/javascript/exif-js/ iOS手机竖着拍的照片经过前端处理之后被旋转了90°的原因以及解决方案 https://w ...

  4. CentOS6X安装PHP5.5

    CentOS6.x默认的php版本是php5.3,已经过时喽,现在最新的稳定版是5.5.38. 安装方法: 1.先下载2个源 rpm -Uvh https://dl.fedoraproject.org ...

  5. c#动态类型

    class Program { static void Main(string[] args) { dynamic test = new ExpandoObject(); test.Name = &q ...

  6. Objective-C之@protocol

    转自:http://www.cnblogs.com/hxxy2003/archive/2011/10/24/2222838.html @protocol是Objective-C中的接口定义方式,也就是 ...

  7. java中的Closeable接口

    一.概述 该接口位于java.io包下,声明例如以下:public interface Closeable Closeable 是能够关闭的数据源或目标. 调用 close 方法可释放对象保存的资源( ...

  8. Mac上搭建直播服务器Nginx

    Mac上搭建直播服务器Nginx 1.安装Homebrew,执行命令 Homebrew简称brew,是Mac OSX上的软件包管理工具,能在Mac中方便的安装软件或者卸载软件,可以说Homebrew就 ...

  9. oracle表空间中PCTFREE, PCTUSED, INITRANS, MAXTRANX参数的解释

    1. PCTFREE 要形容一个 BLOCK 的运作,我们可以把一个 BLOCK 想成一个水杯.侍者把水倒入放在我们面前的水杯,要多满呢,我们要求他倒 9 分满好了,这时候 PCTFREE 代表着设定 ...

  10. STM32F4_TIM输入波形捕获(脉冲频率、占空比)

    推荐 分享一个大神的人工智能教程.零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到人工智能的队伍中来! http://www.captainbed.net/strongerhuang Ⅰ.概述 ...