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