官术网_书友最值得收藏!

How to do it...

  1. Let's add an @EnableScheduling annotation to the BookPubApplication class, as follows:
@SpringBootApplication 
@EnableScheduling 
public class BookPubApplication {...}
  1. 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()); 
} 
  1. 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.
主站蜘蛛池模板: 新竹市| 南汇区| 田林县| 稻城县| 孝昌县| 嘉义市| 芦溪县| 施甸县| 桦川县| 叶城县| 徐水县| 沂水县| 通江县| 永济市| 达州市| 交城县| 郓城县| 丘北县| 太原市| 泗水县| 唐河县| 保康县| 江口县| 丰宁| 临海市| 汕尾市| 银川市| 临洮县| 平凉市| 宣恩县| 峡江县| 青田县| 锦州市| 福建省| 泰安市| 武邑县| 南木林县| 明星| 阿克苏市| 轮台县| 万安县|