From bd19c0733ffa3a36a9b65320826c6ef3b545bfc9 Mon Sep 17 00:00:00 2001
From: xxy <1179705413@qq.com>
Date: Thu, 12 Dec 2019 20:56:13 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=9B=B4=E6=96=B0=E6=A8=A1?=
=?UTF-8?q?=E5=BC=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
novel-front/novel-front.iml | 102 ++++++++++++++++++
.../common/listener/StartListener.java | 35 ++++++
.../common/schedule/CrawlBooksSchedule.java | 42 --------
.../src/main/resources/application.yml | 2 +-
4 files changed, 138 insertions(+), 43 deletions(-)
create mode 100644 novel-front/src/main/java/xyz/zinglizingli/common/listener/StartListener.java
delete mode 100644 novel-front/src/main/java/xyz/zinglizingli/common/schedule/CrawlBooksSchedule.java
diff --git a/novel-front/novel-front.iml b/novel-front/novel-front.iml
index eb5b6e4..1bb4d50 100644
--- a/novel-front/novel-front.iml
+++ b/novel-front/novel-front.iml
@@ -5,4 +5,106 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/novel-front/src/main/java/xyz/zinglizingli/common/listener/StartListener.java b/novel-front/src/main/java/xyz/zinglizingli/common/listener/StartListener.java
new file mode 100644
index 0000000..e991afd
--- /dev/null
+++ b/novel-front/src/main/java/xyz/zinglizingli/common/listener/StartListener.java
@@ -0,0 +1,35 @@
+package xyz.zinglizingli.common.listener;
+
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.ContextRefreshedEvent;
+import org.springframework.stereotype.Component;
+import xyz.zinglizingli.common.crawl.BaseCrawlSource;
+
+@Component
+@Slf4j
+@RequiredArgsConstructor
+public class StartListener implements ApplicationListener {
+
+ private final BaseCrawlSource crawlSource;
+
+ @Override
+ public void onApplicationEvent(ContextRefreshedEvent event) {
+ log.info("程序启动");
+
+
+ while (true) {
+ try {
+ log.debug("crawlBooks执行中。。。。。。。。。。。。");
+ crawlSource.parse();
+ Thread.sleep(1000 * 60 * 5);
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ }
+
+ }
+
+ }
+
+}
diff --git a/novel-front/src/main/java/xyz/zinglizingli/common/schedule/CrawlBooksSchedule.java b/novel-front/src/main/java/xyz/zinglizingli/common/schedule/CrawlBooksSchedule.java
deleted file mode 100644
index 3c1dba5..0000000
--- a/novel-front/src/main/java/xyz/zinglizingli/common/schedule/CrawlBooksSchedule.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package xyz.zinglizingli.common.schedule;
-
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.codec.Charsets;
-import org.springframework.scheduling.annotation.Scheduled;
-import org.springframework.stereotype.Service;
-import org.springframework.web.client.RestTemplate;
-import xyz.zinglizingli.books.service.BookService;
-import xyz.zinglizingli.common.crawl.BaseCrawlSource;
-import xyz.zinglizingli.common.utils.RestTemplateUtil;
-
-/**
- * 更新书籍章节内容定时任务
- *
- * @author 11797
- */
-@Service
-@RequiredArgsConstructor
-@Slf4j
-public class CrawlBooksSchedule {
-
-
- private final BaseCrawlSource crawlSource;
-
-
- /**
- * 10分钟抓取一次
- */
- @Scheduled(fixedRate = 1000 * 60 * 10)
- public void crawBooks() {
-
- log.debug("crawlBooksSchedule执行中。。。。。。。。。。。。");
-
- crawlSource.parse();
-
-
- }
-
-
-
-}
diff --git a/novel-front/src/main/resources/application.yml b/novel-front/src/main/resources/application.yml
index 3298845..5c6bf4c 100644
--- a/novel-front/src/main/resources/application.yml
+++ b/novel-front/src/main/resources/application.yml
@@ -5,7 +5,7 @@ spring:
datasource:
url: jdbc:mysql://127.0.0.1:3306/books?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
username: root
- password: test123456
+ password:
# url: jdbc:mysql://127.0.0.1:3306/books?useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
# username: root
# password: test123456