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

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.
主站蜘蛛池模板: 县级市| 新河县| 临泉县| 九龙城区| 淮安市| 安仁县| 唐河县| 乃东县| 怀宁县| 高雄市| 高淳县| 卢湾区| 吉木萨尔县| 垣曲县| 大邑县| 拉孜县| 曲阳县| 婺源县| 石嘴山市| 内黄县| 屏山县| 临洮县| 溧阳市| 枣庄市| 宁远县| 陇川县| 奇台县| 汨罗市| 汕尾市| 红原县| 息烽县| 江门市| 成都市| 清流县| 岱山县| 明水县| 共和县| 康马县| 永修县| 寿阳县| 通山县|