Spring Boot : Command Line Application

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.

  1.  implements the CommandLineRunner interface.
  2.  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;
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);
public void run(Stringstrings) throws Exception {
LOGGER.info(" ***** Greetings from http://www.SpringBootDev.com ***** ");


How to build and run the application?
maven clan install

java -jar target/spring-boot-commandline-application-0.0.1-SNAPSHOT.jar


Full source code of this post can be found at GitHub

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s