spring3以上版本,spring-content自带 spring-task ,来解决工程中的定时问题

 基于注解配置spring定时任务

spring配置文件如下:

<?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:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:util="http://www.springframework.org/schema/util"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd "> <mvc:annotation-driven /> <context:component-scan base-package="com" /> <!--开启该组件就可以,基于注解使用定时任务啦 -->
<task:annotation-driven /> </beans>

java代码中的书写规范:

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; @Service
public class Demo
{
@Scheduled(cron = "*/5 * * * * ?")
public void tast()
{
System.out.println("定时任务");
}
}

spring-task解决定时问题的更多相关文章

  1. 基于Spring Task的定时任务调度器实现

    在很多时候,我们会需要执行一些定时任务 ,Spring团队提供了Spring Task模块对定时任务的调度提供了支持,基于注解式的任务使用也非常方便. 只要跟需要定时执行的方法加上类似 @Schedu ...

  2. spring task 实现定时执行(补充:解决定时任务执行2次问题)

    首先在spring-mvc.xml配置头文件引入: xmlns:task="http://www.springframework.org/schema/task" 其次引入task ...

  3. Spring中实现定时调度

    1,   内容简介 所谓的定时调度,是指在无人值守的时候系统可以在某一时刻执行某些特定的功能采用的一种机制,对于传统的开发而言,定时调度的操作分为两种形式: 定时触发:到某一时间点上执行某些处理操作: ...

  4. Spring Task中的定时任务无法注入service的解决办法

    1.问题 因一个项目(使用的是Spring+SpringMVC+hibernate框架)需要在spring task定时任务中调用数据库操作,在使用 @Autowired注入service时后台报错, ...

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

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

  6. Spring定时任务解决博客缓存数据更新问题

    最近在做博客系统的时候,由于很多页面都有右边侧边栏,内容包括博客分类信息,归档日志,热门文章,标签列表等,为了不想每次访问页面都去查询数据库,因为本身这些东西相对来说是比较固定的,但是也有可能在网站后 ...

  7. Spring task定时任务执行一段时间后莫名其妙停止的问题

    前因: 我写了一个小项目,主要功能是用Spring task定时任务每天定时给用户发送邮件.执行了几个月一直没有问题,前几天,莫名其妙的突然不再发送邮件了. 只好花费一些时间来查看到底是什么原因造成的 ...

  8. Spring Task 定时任务

    所谓定时任务.就是依据我们设定的时间定时运行任务,就像定时发邮件一样,设定时间到了.邮件就会自己主动发送. 在Spring大行其道的今天,Spring也提供了其定时任务功能,Spring Task.同 ...

  9. 使用Spring Task轻松完成定时任务

    一.背景 最近项目中需要使用到定时任务进行库存占用释放的需求,就总结了如何使用Spring Task进行简单配置完成该需求,本文介绍Spring3.0以后自定义开发的定时任务工具, spring ta ...

  10. spring定时任务轮询(spring Task)

    定时任务轮询比如任务自服务器启动就开始运行,并且每隔5秒执行一次. 以下用spring注解配置定时任务.1.添加相应的schema xmlns:task=" xsi:schemaLocati ...

随机推荐

  1. CSS基础学习(二) 之 width min-width max-width属性

    width 1. 设置元素内容区(content area)的宽度. 2. 如果box-szing属性设置为border-box,width表示border area的宽度,如下图 min-width ...

  2. burpsuit 无法导入证书,抓取https的解决办法

    想用burpsuit中转https流量,需要安装证书: 确保浏览器能访问http 后,访问:http://burp/ 点击右上角下载证书. 然后导入,这些网上都有方法. 但如果你试了后: ①提示导入失 ...

  3. redis 序列化存入对象

    redis 序列化存入对象 //序列化 public static byte [] serialize(Object obj){ ObjectOutputStream obi=null; ByteAr ...

  4. webpack点滴

    一个比较完整的webpack的配置,自己配置不断更新. const path = require('path') const configs = require('./configs/') const ...

  5. babel-node + Express NodeJS项目搭建指南

    1.搭建Node.js环境 从官网下载安装 2.搭建Express环境 express 是 node.js的短精简的Web框架,官网:http://www.expressjs.com.cn/ 安装: ...

  6. windows 和linux 文件互传

    1.sz +  文件   [拷贝到windows上] 2.rz + 文件 [拷贝到linux上]

  7. Petrozavodsk Winter Camp, Day 8, 2014, Mosaic

    给你三个数字a,b,c,让你用1-m的数字凑出来 结论:有2个1和2个2肯定凑不出来,然后就搜索 #include <bits/stdc++.h> using namespace std; ...

  8. 使用pca/lda降维

    PCA主成分分析 import numpy as np import pandas as pd import matplotlib.pyplot as plt # 用鸢尾花数据集 展示 降维的效果 f ...

  9. Shiro集成web环境[Springboot]-认证与授权

    Shiro集成web环境[Springboot]--认证与授权 在登录页面提交登陆数据后,发起请求也被ShiroFilter拦截,状态码为302 <form action="${pag ...

  10. FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(me

    FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(me ...