Spring Boot CLI

Learn via video courses
Topics Covered

Overview

Many developers prefer to work with the command line. Spring boot provides a command line interface tool to test spring applications as scripts.

Introduction to Spring Boot CLI

The Spring Boot CLI is a Command Line Interface for Spring Boot to get started with spring boot quickly. Spring boot code can run as groovy scripts. Spring Boot CLI is the fastest way to create and test a Spring-based application as scripts.

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Spring Boot CLI Features

  • Interface to run and test spring boot application.
  • Spring boot CLI, internally uses starter and auto-configuration to resolve the dependencies.
  • Supports groovy script without groovy installation.

Spring Boot CLI Environment Setup

  1. Setup JDK - Download the JDK version of your choice from the oracle website. Install it based on the operating system. Set JAVA_HOME and path env variable for your account.
  1. Download CLI You can download the Spring CLI distribution zip or tar.gz from the Spring software repository Extract the archive to the folder of your choice.

extracting-archive-to-folder

  1. Set the environment No specific environment variables are required to run the CLI. However, you may want to set SPRING_HOME to point to a specific installation. Add SPRING_HOME/bin to your PATH environment variable.

set-environment

  1. Verify installation To test if you have successfully installed the CLI, you can run the command spring --version. It should give you the output below:

Common Terminal Commands used in Spring Boot CLI

Some of the commonly used commands used with spring boot CLI are:

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

The Run Command

The run command will allow you to run the groovy script. Its syntax is the following:

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data

The Jar Command

The jar command creates a self-contained executable jar file from a Spring Groovy script. Its syntax is the following:

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data

The Init Command

The init command initializes a new project using Spring Initializr (start.spring.io). Its syntax is the following:

Spring Boot CLI Hello World Example

Let's build a simple hello world application using spring boot CLI. The application exposes one single endpoint, /hello.

  1. Create file helloworld.groovy anywhere in your system.
  2. Add the below code to the created file.

.groovy extension is a must.

Code observation

  • No imports.
  • No build tool.
  • No XML of java configuration.
  1. Run and test Go to the command prompt and navigate to the directory where the groovy file is placed, and run the command:

Command runs the script with an embedded tomcat server on port 8080.

The output of the command:

Invoke the endpoint /hello should return the required response.

invoking-the-endpoints

Conclusions

  • Spring boot offers the spring boot CLI tool.
  • Spring boot CLI is useful in quickly running and testing spring boot applications as a groovy script.
  • Spring boot CLI needs a file with a .groovy extension to run it.
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more