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

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.
主站蜘蛛池模板: 安新县| 高安市| 中方县| 鄂托克前旗| 岳西县| 衡南县| 吉木萨尔县| 青铜峡市| 额尔古纳市| 克什克腾旗| 怀仁县| 托克托县| 桐乡市| 宁都县| 武夷山市| 蚌埠市| 托克托县| 图木舒克市| 姚安县| 肇庆市| 雷州市| 闽清县| 乐业县| 克什克腾旗| 南皮县| 湘西| 九龙县| 泗阳县| 凤庆县| 台前县| 格尔木市| 明溪县| 西林县| 乌恰县| 高唐县| 石嘴山市| 梅河口市| 阳曲县| 和顺县| 长兴县| 莲花县|