Spring Boot Project using Spring Boot CLI

In my previous articles of Spring Boot,Β I have covered the introduction of Spring Boot , Its advantages, limitations, goals, features etc and the Key Components of the Spring Boot.

If you have not read my introduction article of Spring Boot, I would request you to take a look – Β Spring Boot Tutorial.

There exists following ways to create Spring Boot project. We can use any of below mentioned approach to create Spring Boot Application :

We are going to cover here How to develop “Spring Boot Application using Spring Boot CLI”.

Spring Boot Project using Spring Boot CLI

We are using Eclipse IDE for the below example. It is very popular IDE for java projects. You can download it fromΒ here.

Let’s get started :

Step 1 : Download / Install the Spring Boot CLI tool

Spring Boot CLIΒ is a tool provided by The Spring team. This toolΒ is used to run and test the Spring Boot application using command prompt.

Download the Spring Boot CLI tool from here.

Spring Boot CLI

Extract the Downloaded zip file in your System.

Spring Boot CLI

Step 2 : Configure the Spring Boot CLI tool

The downloaded folder will contain two files inΒ binΒ folder –

  • spring (Β for Mac or Linux )
  • spring.bat ( for Windows )

Open Command Prompt and run below command to set theΒ Spring Boot CLI Environment Variables in Windows System :

set PATH=E:\spring-2.1.8.RELEASE\bin;%PATH%

In the above command, write the path where you have stored the downloaded file.

Or Set the path Manually by using below steps in Windows :

Spring Boot CLI

Verify the Installation process by running below command :

spring –version

or

spring –help

Spring Boot CLI

Step 3 : Develop the Application using Spring Boot CLIΒ 

CLI only executes the groovy files. So, let us create one groovy file for our Spring Boot application.

  • Create a file “App.groovy” in your system.
  • Place the below content in created file.
@Controller
class App {
  @RequestMapping("/")
  @ResponseBody
  String app() {
    "Hello World!!"
  }
}
  • @ControllerΒ indicates that class is a Controller.
  • @RequestMappingΒ Β annotation maps HTTP requests to handler methods of controllers.
  • @ResponseBodyΒ is annotation which binds the method return value to the web response body.

Step 4 : Running the Application

Execute the below command in CLI :

spring run App.groovy

Spring Boot CLI

Output :Β 

Spring Boot CLI

Conclusion

That’s all folks! In this article,Β  we have learnt How to develop the Spring Boot Application using ‘Spring Boot CLI’.

Newsletter Updates

Enter your name and email address below to subscribe to our newsletter

Leave a Reply