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 { + } + +}