×
DocsConsole

DocsConsole

Spring Boot CLI HelloWorld App Example

By | | Updated : 2018-10-04 | Viewed : 531 times

Spring Boot CLI HelloWorld App Example

The current article will provide detailed explanation about the Spring Boot CLI Set up which helps to implement the spring boot applications.Here we will create basic application with Spring Boot CLI.

Spring Boot Environment Set Up

Spring Boot Set up can be achieved in two ways.

  • Spring Boot CLI

  • Dependency Management (Maven or Gradle)

Note: First of all, we need to get installed Java 1.8 or above in our System.

Spring Boot CLI installation

Two way for Spring Boot CLI installation are Manual and Automatic.

    For Automatic installation

  • If the OS is Windows, then we can use SDKMAN for Spring Boot CLI installation.

  • If the OS is Mac, then we can use OSX Homebrew for Spring Boot CLI installation.

Note: Please verify the Spring Boot documentation further clarification.

For Manual installation

We need to download the Spring Boot CLI distribution zip from below given Spring software repository. URL for Spring Boot CLI downloading is click here.Here we can get required Spring Boot CLI as Zip/tar file for Windows / Linux. Spring-2.1.0.M1 is the version used here. The below given image is displaying all the files After unpaking zip.

We need to download the Spring Boot CLI distribution zip from below given Spring software repository. URL for Spring Boot CLI downloading is click here.Here we can get required Spring Boot CLI as Zip/tar file for Windows / Linux. Spring-2.1.0.M1 is the version used here. The below given image is displaying all the files After unpaking zip.

Unpacking of Spring Boot CLI

After unpacking the zip/tar file, we need to set up the path environment variable. The below command is for set up environment variable. This is for temporary option. We can do it permanently by modifying the path in Advanced system settngs.

set PATH=D:\Installation-Home\spring-2.1.4.RELEASE\bin;%PATH%
Path set up for Spring Boot CLI

To test the Spring Boot CLI installation, execute the below given commands.

Spring --version displays the version of Spring Boot
spring help will show the list of all the possible options/Commands

Please find the below given screen shot for the same.

Spring Boot CLI installation Testing

Spring Boot HelloWorld-App with Spring Boot CLI

If you observe the possible option for Spring command, it will also be useful for executing the groovy script. We will follow the below given steps to create the basic application by using the Spring Boot CLI.

Create the folder named with SpringCLIHelloWorld and create one groovy file named with HelloWorld.groovy. Here groovy is the file extension.

The HelloWorld.groovy file content has to be changed as given below.

HelloWorld.groovy
@RestController
class HelloWorld {
  @RequestMapping("/")
  String hello() {
    "Hello Spring Boot CLI World."
  }
}

Here we have created one controller. For each request, it will give the response. To run the above groovy script, we need to navigate the project root folder SpringCLIHelloWorld in command prompt and then execute the below given command.

spring run HelloWorld.groovy

The below given screen shot will display the server start up after firing the above command.

Spring Boot CLI Hello world example

Please fire the below given URL and the result will be displayed as below given screen shot.

http://localhost:8080/

Spring Boot CLI Hello World
Leave A Reply