上QQ阅读APP看书,第一时间看更新
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.