Browse Source

增加定时任务,定时发送B2B短信

wangyc 7 years ago
parent
commit
7fdb69dd89
1 changed files with 31 additions and 0 deletions
  1. 31 0
      src/main/java/com/uas/ps/message/SchedulingConfig.java

+ 31 - 0
src/main/java/com/uas/ps/message/SchedulingConfig.java

@@ -0,0 +1,31 @@
+package com.uas.ps.message;
+
+import com.uas.ps.message.service.MessageService;
+import javax.annotation.Resource;
+import org.apache.log4j.Logger;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+
+/**
+ * Created by wangyc on 2018/1/31.
+ *
+ * @version 2018/1/31 19:16 wangyc
+ */
+@Configuration
+@EnableScheduling
+public class SchedulingConfig {
+    private final Logger logger = Logger.getLogger(Logger.class);
+
+    @Resource
+    private MessageService messageService;
+
+    /**
+     * 定时执行发送任务
+     */
+    @Scheduled(cron = "0 0 9 * * ?") // 每10分钟执行一次
+    public void getToken() {
+        logger.info("getToken定时任务启动");
+        messageService.sendMessage("{\"consumerApp\":\"B2B\"}");
+    }
+}