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