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

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(); 
} 
主站蜘蛛池模板: 梧州市| 凤山市| 宁国市| 福建省| 兴义市| 东宁县| 贺兰县| 休宁县| 祁东县| 五常市| 柘城县| 始兴县| 车致| 朔州市| 长泰县| 大悟县| 天祝| 清河县| 沙湾县| 台北县| 班玛县| 九龙县| 临沭县| 乌鲁木齐县| 闸北区| 车险| 治县。| 杭锦后旗| 黄骅市| 集贤县| 磐安县| 邵阳市| 隆化县| 曲周县| 哈巴河县| 若羌县| 宣恩县| 即墨市| 苍梧县| 金乡县| 昭觉县|