繁体   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