ont mage image util spring 实现 for not
- 1 package com.wisezone.service;
- 2
- 3 import java.text.SimpleDateFormat;
- 4 import java.util.Date;
- 5
- 6 import org.springframework.scheduling.annotation.Scheduled;
- 7 import org.springframework.stereotype.Service;
- 8
- 9 @Service
- 10 public class JobService {
- 11
- 12 public void job02(){
- 13System.out.println("定时输出任务:"+newSimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()));
- 14 }
- 15}
- 1 package com.wisezone.test;
- 2
- 3 import org.springframework.context.ApplicationContext;
- 4 import org.springframework.context.support.ClassPathXmlApplicationContext;
- 5
- 6 public class Test
- 7 {
- 8 public static void main(String[] args)
- 9 {
- 10ApplicationContext app =newClassPathXmlApplicationContext("beans.xml");
- 11
- 12 }
- 13}
- 1 2 3xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4xmlns:context="http://www.springframework.org/schema/context" 5 xmlns:task="http://www.springframework.org/schema/task"
- 6xsi:schemaLocation="
- 7http://www.springframework.org/schema/beans
- 8http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
- 9http://www.springframework.org/schema/context
- 10http://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 ">
- 1314package="com.wisezone" />15[email protected]-->16
- 17
- 18 <!-- XML方式实现spring定时任务 -->
- 19 <task:scheduled-tasks>
- 20 <task:scheduled ref="jobService" method="job02" cron="0/2 * * * * ?"/>
- 21 </task:scheduled-tasks>
- 22
结果:
Spring 通过 XML 方式实现定时任务
来源: http://www.bubuko.com/infodetail-2047891.html