Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
What is Command Line Runner Interface in Spring Boot?
Next article icon

What is Command Line Runner Interface in Spring Boot?

Last Updated : 13 Dec, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

Spring Boot CLI (Command Line Interface) is a command line software or tool. This tool is provided by the Spring framework for quickly developing and testing Spring Boot applications from the command prompt. In this article, we will discuss the command line runner interface in the spring boot.

Spring Boot CLI

The Spring Boot CLI (Command Line Interface) is present in the dependency of the org.springframework.boot that is used to quickly bootstrap the spring boot application. CLI in Spring Boot contains a run method() that is executed after the application startup. Geeks, if you do find it not easy to grasp then do have a prior understanding of Spring Initializr.

Method Invoked: Overridden run()

void run(String ..arg)
  • Parameter: This method contains varargs parameters for handling multiple string objects.
  • Return type: It doesn't return anything (void)

We do use it because if it's associative advantages of using the command line runner interface as described. Debugging is very easy using the command-line runner interface because we don't need to explicitly call the particular resources via API calls, we can call them using the run method of the command-line runner interface that is executed immediately once the application is executed successfully.

Let's understand the functionality of this interface using an example, so Spring Initializr is basically a web-based tool using which we can easily generate the structure of the Spring Boot project. It also provides various different features for the projects expressed in a metadata model. This model allows us to configure the list of dependencies that are supported by JVM. Here, we will create the structure of an application using a spring initializer, therefore, to do this, the following steps as depicted below media sequentially as follows:

Steps to print Hello World in Spring Boot CLI:

  1. Go to Spring Initializr
  2. Fill in the details as per the requirements.
  3. Click on Generate which will download the starter project
  4. Extract the zip file.
  5. Go to SpringBootAppApplication class
  6. Run the SpringBootAppApplication class and wait for the Tomcat server

Step 1: Go to Spring Initializr

Project Metadata

Step 2: Fill in the details as per the requirements. For this application:

Project: Maven
Language: Java
Spring Boot: 3.2.0
Packaging: JAR
Java: 17
Dependencies: Spring Web

Step 3: Click on Generate which will download the starter project.

Step 4: Extract the zip file. Now open a suitable IDE and then go to File->New->Project from existing sources->Spring-boot-app and select pom.xml. Click on import changes on prompt and wait for the project to sync.

Importing Project

Note: In the Import Project for Maven window, make sure you choose the same version of JDK which you selected while creating the project.

Step 5: Go to src -> main -> java -> SpringBootAppApplication

SpringBootAppApplication.java

Java
@SpringBootApplication // Main class // Implementing CommandLineRunner interface public class SpringBootAppApplication implements CommandLineRunner  {      // Method 1     // run() method for springBootApplication to execute     @Override     public void run(String args[]) throws Exception      {          // Print statement when method is called         System.out.println("HEllo world");     }      // Method 2     // Main driver method     public static void main(String[] args)      {          // Calling run() method to execute SpringBootApplication by         // invoking run() inside main() method         SpringApplication.run(SpringBootAppApplication .class, args);     } } 

This application is now ready to run. 

Step 6: Run the SpringBootAppApplication class and wait for the Tomcat server to start where the default port is already set.

Tip: The default port of the Tomcat server is 8080 and can be changed in the application.properties file.

Output: Generated on terminal/CMD 

Output on terminal

If we want to print something, we have to call using API that is why the command-line runner interface is helpful.


Next Article
What is Command Line Runner Interface in Spring Boot?

Z

zack_aayush
Improve
Article Tags :
  • Java
  • Java-Spring-Boot
Practice Tags :
  • Java

Similar Reads

    Spring Boot - Difference Between CrudRepository and JpaRepository
    Spring Boot is built on the top of the spring and contains all the features of spring. And is becoming a favorite of developers these days because of its rapid production-ready environment which enables the developers to directly focus on the logic instead of struggling with the configuration and se
    3 min read
    Spring Boot - CrudRepository with Example
    Spring Boot is built on the top of the spring and contains all the features of spring. And is becoming a favorite of developers these days because of its rapid production-ready environment which enables the developers to directly focus on the logic instead of struggling with the configuration and se
    6 min read
    Spring Boot - application.yml/application.yaml File
    Spring is widely used for creating scalable applications. For web applications Spring provides. In Spring Boot, whenever we create a new Spring Boot Application in spring starter, or inside an IDE (Eclipse or STS) a file is located inside the src/main/resources folder named as application.properties
    4 min read
    Spring Boot - CRUD Operations using MySQL Database
    CRUD stands for Create, Read/Retrieve, Update and Delete and these are the four basic operations that we perform on persistence storage. CRUD is data-oriented and the standardized use of HTTP methods. HTTP has a few methods which work as CRUD operations and do note they are very vital from a develop
    7 min read
    How to Implement One to Many Mapping in Spring Boot?
    Spring Boot is built on the top of the spring and contains all the features of spring. Spring also provides JPA and hibernate to increase the data manipulation efficiency between the spring application and the database. In very simple terms we can say JPA (Java persistence API) is like an interface
    3 min read
    How to Run Your First Spring Boot Application in Eclipse IDE?
    Spring Boot is built on the top of the spring and contains all the features of spring. And is becoming a favorite of developers these days because of its rapid production-ready environment which enables the developers to directly focus on the logic instead of struggling with the configuration and se
    3 min read
    How to Run Spring Boot Application?
    Spring Boot is built on the top of Spring and contains all the features of Spring. And it is becoming a favorite of developers these days because of its rapid production-ready environment which enables the developers to directly focus on the logic instead of struggling with the configuration and set
    8 min read
    Spring Boot - Application Properties
    Spring Boot is built on top of the Spring Framework and includes all its features while simplifying configuration and setup. It has become a favorite among developers because it provides a rapid, production-ready environment that allows them to focus on business logic instead of dealing with complex
    3 min read
    Spring Boot with H2 Database
    H2 Database in Spring Boot is an embedded, open-source, and in-memory database. It is a relational database management system written in Java. It is a client/server application. It stores data in memory, not persist the data on disk. Here we will be discussing how can we configure and perform some b
    6 min read
    Spring Boot - CRUD Operations
    CRUD stands for Create, Read/Retrieve, Update, and Delete and these are the four basic operations that we perform on persistence storage. CRUD is data-oriented and the standardized use of HTTP methods or there is a term for this called HTTP action verbs. HTTP has a few action verbs or methods that w
    7 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences