[英]How to bootstrap SpringBoot application (without mvc)?
我想對某些測試應用程序使用spring-data&IOC容器。
問題是:如何引導應用程序? 在使用spring-mvc的情況下,我們從控制器中移出,但是如何在沒有mvc的情況下這樣做呢?
我的代碼需要一些類似於main的方法,但是應用程序public static void main
已經用於spring初始化:
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
那么,我應該在哪里放置代碼?
有一個CommandLineRunner
接口只是意味着要這樣做。
@Service
class FooBar implements CommandLineRunner {
// Inject whatever collaborator you need
@Override
void run(String... args) throws Exception {
// Execute whatever you need.
// command-line arguments are available if you need them
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.