您的位置:首页 > 编程语言 > Java开发

Spring 定时任务设置

2018-03-30 22:39 218 查看
package com.westcredit.modules.test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.westcredit.common.persistence.MapEntity;
import com.westcredit.common.utils.IdGen;
import com.westcredit.modules.person.service.PersonService;
@Service
public class CalculationCreditPromiseIsStopTask {
@Autowired
PersonService personService;

private static transient Logger logger = LoggerFactory.getLogger(CalculationCreditPromiseIsStopTask.class);
@Autowired
public void execute() { 
    logger.info("信用承诺是否过期---------------------------------开始--------------------------------");
    MapEntity e =new MapEntity();
   
    e.put("name","zhangdong");
    e.put("state", 1);
    e.put("address", "商南金丝峡");
    e.put("del_flag","1");
    for(int i=0;i<10;i++){
    e.put("id",IdGen.uuid());
    e.put("meeting","开会"+i);
    personService.save(e);
    }
   

   } 
}

配置文件
<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:task="http://www.springframework.org/schema/task"  
    xmlns:context="http://www.springframework.org/schema/context"  
    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.0.xsd  
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd    
    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd    
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd    
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd    
    http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
    ">  

    <!-- 配置注解扫描 -->
    <context:component-scan base-package="com.westcredit"/>

    <task:scheduler id="taskScheduler" pool-size="10" />

    <task:scheduled-tasks scheduler="taskScheduler">
        <!-- 每天23点 10分 20分 30分 40分 各执行一次
        <task:scheduled ref="flmMechantAmtCountTask" method="execute" cron="0 10,20,30,40 23 * * ?"/>
        -->
        <task:scheduled ref="calculationCreditPromiseIsStopTask" method="execute" cron="0 0/2 * * * ?"/>
         
    </task:scheduled-tasks>

</beans>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: