- Spring Boot 2.0 Cookbook(Second Edition)
- Alex Antonov
- 102字
- 2021-06-24 19:24:37
How to do it...
- 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"); }
}
- 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(); }
推薦閱讀
- MySQL數據庫進階實戰
- Lean Mobile App Development
- WS-BPEL 2.0 Beginner's Guide
- INSTANT Cytoscape Complex Network Analysis How-to
- Starling Game Development Essentials
- 大數據技術入門
- Google Cloud Platform for Developers
- MySQL技術內幕:SQL編程
- 二進制分析實戰
- SIEMENS數控技術應用工程師:SINUMERIK 840D-810D數控系統功能應用與維修調整教程
- Access 2010數據庫程序設計實踐教程
- 改進的群智能算法及其應用
- Cognitive Computing with IBM Watson
- 數據挖掘與機器學習-WEKA應用技術與實踐(第二版)
- 碼上行動:利用Python與ChatGPT高效搞定Excel數據分析