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

How to do it...

  1. Create the file named StartupRunner.java under the src/main/java/com/example/bookpub/ directory from the root of our project with the following content:
        package com.example.bookpub; 

import com.example.bookpub.repository.BookRepository; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner;
import org.springframework.scheduling.annotation.Scheduled;

public class StartupRunner implements CommandLineRunner { protected final Log logger = LogFactory.getLog(getClass()); @Override public void run(String... args) throws Exception { logger.info("Hello"); }
}
  1. After we have defined the class, let's proceed by defining it as @Bean in the BookPubApplication.java application configuration, which is located in the same folder as our newly created StartupRunner.java file as follows:
@Bean 
public StartupRunner schedulerRunner() { 
    return new StartupRunner(); 
} 
主站蜘蛛池模板: 许昌县| 绿春县| 区。| 介休市| 沧州市| 阳谷县| 新蔡县| 同心县| 紫金县| 寿宁县| 乌兰浩特市| 抚松县| 白银市| 达州市| 义马市| 车致| 平果县| 河津市| 廉江市| 天气| 虞城县| 马边| 图片| 洪泽县| 大理市| 循化| 新营市| 枝江市| 百色市| 沐川县| 花莲县| 宜川县| 乡宁县| 朔州市| 永嘉县| 黄梅县| 武陟县| 阿拉善右旗| 天镇县| 鄂伦春自治旗| 尚志市|