Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Non-Web application in spring boot [closed]

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?

like image 452
rishi Avatar asked Aug 03 '16 11:08

rishi


People also ask

Can spring boot be used for non web application purposes?

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.

Is spring boot used only for web applications?

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.

What are non web applications?

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.

What is standalone application in spring boot?

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.


1 Answers

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);
    }

}
like image 134
Alexandru Marina Avatar answered Sep 21 '22 10:09

Alexandru Marina