- Spring Boot 2.0 Cookbook(Second Edition)
- Alex Antonov
- 104字
- 2021-06-24 19:24:39
How to do it...
- Let's add an @EnableScheduling annotation to the BookPubApplication class, as follows:
@SpringBootApplication @EnableScheduling public class BookPubApplication {...}
- As a @Scheduled annotation can be placed only on methods without arguments, let's add a new run() method to the StartupRunner class and annotate it with the @Scheduled annotation, as shown in the following line:
@Scheduled(initialDelay = 1000, fixedRate = 10000) public void run() { logger.info("Number of books: " + bookRepository.count()); }
- Start the application by executing ./gradlew clean bootRun from the command line so as to observe the Number of books: 0 message that shows in the logs every 10 seconds.
推薦閱讀
- PyTorch深度學習實戰:從新手小白到數據科學家
- 復雜性思考:復雜性科學和計算模型(原書第2版)
- Python金融大數據分析(第2版)
- Voice Application Development for Android
- 云計算服務保障體系
- R數據科學實戰:工具詳解與案例分析(鮮讀版)
- 從0到1:JavaScript 快速上手
- 區塊鏈技術應用與實踐案例
- Mastering ROS for Robotics Programming(Second Edition)
- Deep Learning with R for Beginners
- 信息融合中估計算法的性能評估
- PostgreSQL高可用實戰
- 數據挖掘與機器學習-WEKA應用技術與實踐(第二版)
- NoSQL數據庫原理(第2版·微課版)
- Practical Convolutional Neural Networks