Nearby lessons

4 of 10

Spring Boot - CLI Commands

📌 What You Will Learn
  • Understand Spring Boot - CLI Commands
  • See working code examples
  • Learn from common mistakes and Q&A

Learn Spring Boot - CLI Commands step by step — simple explanations, complete programs with their output, common beginner mistakes, and exam-style MCQs.

Spring Boot CLI commands

  • spring --version --> To get Spring CLI version.
  • spring --version --> To get help for Spring CLI.
  • spring run Groovy_Script_File_Name.groovy --> to run Groovy Script
  • Prepare Groovy Script Code:

--------------------------------

It is almost all same as JAVA code only, but, the file extension should be .groovy.

EX: D:\spring_boot_practice\cli\HelloController.groovy

--------------------------------------------------------

@RestController

public class HelloController{

@RequestMapping("/hello")

public String sayhello(){

return "Hello User!";

}

}

  • If 8080 is busy then change tomcat port number from 8080 to 1234 by providing

application.properties file at the same location:

-------------------------------------------------------------------------------------------------------------------------

---------

D:\spring_boot_practice\cli\application.properties

--------------------------------------------------

server.port=1234

  • Run Groovy Script code through Spring Boot CLI.

---------------------------------------------------

Spring Boot CLI commands

D:\spring_boot_practice\cli>spring run HelloController.groovy

Example02
JCode Cell
1 
2Run Groovy Script code by using "spring run" command.
3
📝 Key Takeaways
  • Key ideas of Spring Boot - CLI Commands explained simply
  • Ready-to-use code examples
  • Exam-style questions at the end