簡體   English   中英

如何引導SpringBoot應用程序(不帶mvc)?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM