春季启动时的非Web应用程序

ris*_*shi 6 spring spring-boot

我刚开始学习Spring-Boot.我使用gradle创建了简单的Spring-Boot Web应用程序.但我想要一个非Web应用程序项目,我可以从PSVM运行所有代码,我还必须删除tomcat依赖项.我搜索了一下但没有例子.

使Spring Boot应用程序上下文作为非Web应用程序上下文启动需要什么?

小智 12

Spring Boot提供了一些示例应用程序:https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples.简单的命令行示例如下:https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-simple

从引用的示例项目中,关键是要实现的主类CommandLineRunner- 这是示例项目中的代码:

@SpringBootApplication
public class SampleSimpleApplication implements CommandLineRunner {
    // ...

    @Override
    public void run(String... args) {
        // ...
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(SampleSimpleApplication.class, args);
    }

}
Run Code Online (Sandbox Code Playgroud)