package com.wisezone.service;

 import java.text.SimpleDateFormat;
import java.util.Date; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; @Service
public class JobService { public void job02(){
System.out.println("定时输出任务:"+new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()));
}
}
 package com.wisezone.test;

 import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class Test
{
public static void main(String[] args)
{
ApplicationContext app = new ClassPathXmlApplicationContext("beans.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:context="http://www.springframework.org/schema/context"
5 xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
11 http://www.springframework.org/schema/task
12 http://www.springframework.org/schema/task/spring-task-3.2.xsd ">
<!-- 扫描包基础目录 -->
<context:component-scan base-package="com.wisezone" />
<!-- 识别@Scheduled注解 -->
<task:annotation-driven/> 18 <!-- XML方式实现spring定时任务 -->
19 <task:scheduled-tasks>
20 <task:scheduled ref="jobService" method="job02" cron="0/2 * * * * ?"/>
21 </task:scheduled-tasks>
</beans>

结果:

Spring通过XML方式实现定时任务的更多相关文章

  1. Spring基于XML方式的使用

    一.IoC配置 IoC的配置是通过Spring的xml文件的bean标签进行的. 1.bean标签介绍 bean标签一般是在xml文件进行配置的,xml文件一般样式如下: <?xml versi ...

  2. 【Spring】XML方式实现(无参构造 有参构造)和注解方式实现 IoC

    文章目录 Spring IoC的实现方式 XML方式实现 通过无参构造方法来创建 1.编写一个User实体类 2.编写我们的spring文件 3.测试类 UserTest.java 4.测试结果 通过 ...

  3. Spring通过注解方式实现定时任务

    XML配置: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http:/ ...

  4. Spring基于XML方式加载Bean定义信息(又名:Spring IOC源码时序图)-图解

  5. spring aop 使用xml方式的简单总结

    spring aop的 xml的配置方式的简单实现: 1.编写自己的切面类:配置各个通知类型 /** * */ package com.lilin.maven.service.aop; import ...

  6. 使用spring框架,用xml方式进行bean装配出现“The fully qualified name of the bean's class, except if it serves...”

    使用spring框架,用xml方式进行bean装配出现“The fully qualified name of the bean's class, except if it serves...”. 原 ...

  7. Spring框架中的Quartz定时任务使用笔记(通过@Scheduled注解的方式实现)

    1.修改spring的xml配置信息 applicationContext.xml 三个部分内容 1.xmlns添加:xmlns:task="http://www.springframewo ...

  8. 跟着刚哥学习Spring框架--通过XML方式配置Bean(三)

    Spring配置Bean有两种形式(XML和注解) 今天我们学习通过XML方式配置Bean 1. Bean的配置方式 通过全类名(反射)的方式   √ id:标识容器中的bean.id唯一. √ cl ...

  9. Spring声明式事务管理(基于XML方式实现)

    --------------------siwuxie095                             Spring 声明式事务管理(基于 XML 方式实现)         以转账为例 ...

随机推荐

  1. OS路径模块命令

    os.remove():删除指定文件os.rmdir():删除指定目录os.mkdir():创建单级目录os.makedirs():创建多级目录os.listdir(dirname):列出dirnam ...

  2. Qt下TCP编程

    一.服务器 1.声明一个QTcpServer对象 QTcpServer* serverListener; 2.new出对象 this->serverListener = new QTcpServ ...

  3. 斯坦福机器学习视频笔记 Week4 & Week5 神经网络 Neural Networks

    神经网络是一种受大脑工作原理启发的模式. 它在许多应用中广泛使用:当您的手机解释并理解您的语音命令时,很可能是神经网络正在帮助理解您的语音; 当您兑现支票时,自动读取数字的机器也使用神经网络. Non ...

  4. Asp.net 5 (MVC6) Areas 分区

    1. Startup.cs 类的 Configure方法中, 加入Area路由设置代码: //app.UseMvcWithDefaultRoute(); app.UseMvc(routes=> ...

  5. 微信小程序与微信公众号同一用户登录问题

    微信小程序与微信公众号同一用户登录问题 最近在做微信小程序与微信公众号登录合并的接口.整理相关资料以及个人认识的心得写了这篇文章与大家一起分享. 首先,简单说下我遇到的问题是我们的程序调用微信小程序得 ...

  6. iphone的一些坑

    1.<div contenteditable></div>需要添加css user-select: text;才能输入. 2.css属性animation一直存在,添加了-we ...

  7. 使用log4j2打印Log,log4j不能打印日志信息,log4j2不能打印日志信息,log4j和logj2,idea控制台信息乱码(文末)

    说来惭愧,今天就写了个"hello world",了解了一下log4j的日志. 本来是想在控制台打印个log信息,也是遇到坎坷重重,开始也没去了解log4j就来使用,log4j配置 ...

  8. numpy 往array里添加一个元素

    首先这里p_arr为一个numpy的array,p_为一个元素 p_arr = np.concatenate((p_arr,[p_])) # 先将p_变成list形式进行拼接,注意输入为一个tuple ...

  9. 安装rackspace private cloud --3 Deployment host

    on deploy host: 在deploy host上安装 Ubuntu Server 14.04 (Trusty Tahr) LTS 64-bit # apt-get install aptit ...

  10. 一个渣渣tomcat的学习成果.

    //////////////////////////////////////写在前面////////////////////////////////////// 时隔几个月,恢复更新了,之前由于一些私 ...