You can use https://start.spring.io to generate the spring boot application as you are already aware.
It is very easy to create a spring boot application that is run on command line. You need to follow only two simple steps.
- implements the CommandLineRunner interface.
- override the run() method
if you have done above two steps, you are done with building the command line application with spring boot. here is the sample code segment.
package com.springbootdev.samples.springbootcommandlineapplication; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import org.springframework.boot.CommandLineRunner; | |
import org.springframework.boot.SpringApplication; | |
import org.springframework.boot.autoconfigure.SpringBootApplication; | |
@SpringBootApplication | |
public class SpringBootCommandlineApplication implements CommandLineRunner { | |
private static final Logger LOGGER = LoggerFactory.getLogger(SpringBootCommandlineApplication.class); | |
public static void main(String[] args) { | |
SpringApplication.run(SpringBootCommandlineApplication.class, args); | |
} | |
@Override | |
public void run(String… strings) throws Exception { | |
LOGGER.info(" ***** Greetings from http://www.SpringBootDev.com ***** "); | |
} | |
} |
https://gist.github.com/chathurangat/591bdf2245dad953f58f4693c07378bf.js
How to build and run the application?
Build maven clan install Run java -jar target/spring-boot-commandline-application-0.0.1-SNAPSHOT.jar
Full source code of this post can be found at GitHub