如何引导SpringBoot应用程序(没有mvc)?
我想为一些测试应用程序使用spring数据和IOC容器 问题是:如何引导应用程序? 在SpringMVC的情况下,我们从控制器转移,但是没有mvc怎么做呢 我的代码需要一些类似main的方法,但是应用程序如何引导SpringBoot应用程序(没有mvc)?,spring,spring-boot,Spring,Spring Boot,我想为一些测试应用程序使用spring数据和IOC容器 问题是:如何引导应用程序? 在SpringMVC的情况下,我们从控制器转移,但是没有mvc怎么做呢 我的代码需要一些类似main的方法,但是应用程序publicstaticvoidmain已经用于spring初始化: @SpringBootApplication public class App { public static void main(String[] args) { SpringApplication
publicstaticvoidmain
已经用于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
}
}
或者,如果使用Spring Boot>=1.3.0,则可以使用更容易访问命令行参数的
ApplicationRunner