I have just started learning Spring-Boot. I have created simple Spring-Boot web-application using gradle. BUT I want a non-web application project where I can run all code from PSVM and also I have to remove tomcat dependency. I searched about it but got no example.
What is needed to make the Spring Boot application context start as a non-web application context?
The application can also be called as Spring Boot Standalone application. To develop a non web application, your Application needs to implement CommandLineRunner interface along with its run method. This run method acts like a main of your application.
However, Spring Boot has a number of uses that do not require a web server: console applications, job scheduling, batch or stream processing, serverless applications, and more. In this tutorial, we'll look at several different ways to use Spring Boot without a web server.
Web-based apps are designed for access via a Web browser or an application client that serves as a user interface. Non-Web-based applications are intended for offline use. Building this type of application has some drawbacks that the programmer should keep in mind during the development phase.
Spring Boot makes it easy to create stand-alone, production-grade Spring-based applications. Spring Boot provides various starters for building standalone or more traditional war deployments. We will create Spring Boot standalone application by implementing CommnadLineRunner interface.
Spring Boot provides some example applications: https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples. The simple command line sample would be this one: https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-simple
From the referenced example project, the key is for the main class to implement CommandLineRunner
- here is the code from the example project:
@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);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With