From e8ec3f0ebf69dd65e3b69bc5c104a61652dbb48b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8C=BFDD?= Date: Sun, 15 May 2016 10:46:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Chapter4-1-1/pom.xml | 50 +++++++++++++++++++ .../main/java/com/didispace/Application.java | 15 ++++++ .../com/didispace/task/ScheduledTasks.java | 19 +++++++ .../src/main/resources/application.properties | 0 .../java/com/didispace/ApplicationTests.java | 18 +++++++ 5 files changed, 102 insertions(+) create mode 100644 Chapter4-1-1/pom.xml create mode 100644 Chapter4-1-1/src/main/java/com/didispace/Application.java create mode 100644 Chapter4-1-1/src/main/java/com/didispace/task/ScheduledTasks.java create mode 100644 Chapter4-1-1/src/main/resources/application.properties create mode 100644 Chapter4-1-1/src/test/java/com/didispace/ApplicationTests.java diff --git a/Chapter4-1-1/pom.xml b/Chapter4-1-1/pom.xml new file mode 100644 index 0000000..6af0e72 --- /dev/null +++ b/Chapter4-1-1/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + + com.didispace + Chapter4-1-1 + 1.0.0 + jar + + Chapter4-1-1 + Spring Boot project + + + org.springframework.boot + spring-boot-starter-parent + 1.3.2.RELEASE + + + + + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/Chapter4-1-1/src/main/java/com/didispace/Application.java b/Chapter4-1-1/src/main/java/com/didispace/Application.java new file mode 100644 index 0000000..b972234 --- /dev/null +++ b/Chapter4-1-1/src/main/java/com/didispace/Application.java @@ -0,0 +1,15 @@ +package com.didispace; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.annotation.EnableScheduling; + +@SpringBootApplication +@EnableScheduling +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/Chapter4-1-1/src/main/java/com/didispace/task/ScheduledTasks.java b/Chapter4-1-1/src/main/java/com/didispace/task/ScheduledTasks.java new file mode 100644 index 0000000..7c52db6 --- /dev/null +++ b/Chapter4-1-1/src/main/java/com/didispace/task/ScheduledTasks.java @@ -0,0 +1,19 @@ +package com.didispace.task; + +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.text.SimpleDateFormat; +import java.util.Date; + +@Component +public class ScheduledTasks { + + private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); + + @Scheduled(fixedRate = 5000) + public void reportCurrentTime() { + System.out.println("现在时间:" + dateFormat.format(new Date())); + } + +} diff --git a/Chapter4-1-1/src/main/resources/application.properties b/Chapter4-1-1/src/main/resources/application.properties new file mode 100644 index 0000000..e69de29 diff --git a/Chapter4-1-1/src/test/java/com/didispace/ApplicationTests.java b/Chapter4-1-1/src/test/java/com/didispace/ApplicationTests.java new file mode 100644 index 0000000..22c3fe6 --- /dev/null +++ b/Chapter4-1-1/src/test/java/com/didispace/ApplicationTests.java @@ -0,0 +1,18 @@ +package com.didispace; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = Application.class) +public class ApplicationTests { + + + @Test + public void getHello() throws Exception { + } + +}