Spring Boot Resources

Spring Boot - Quick Start using CLI



This chapter will teach you how to create a Spring Boot application using Maven and Gradle.

Prerequisites

Your system need to have the following minimum requirements to create a Spring Boot application −

  • Java 17
  • Maven 3.6.3
  • Gradle 7.5

Spring Boot CLI

The Spring Boot CLI is a command line tool and it allows us to run the Groovy scripts. This is the easiest way to create a Spring Boot application by using the Spring Boot Command Line Interface. You can create, run and test the application in command prompt itself.

This section explains you the steps involved in manual installation of Spring Boot CLI. For further help, you can use the following link: https://docs.spring.io/spring-boot/installing.html

You can also download the Spring CLI distribution from the Spring Software repository at: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-cli/3.5.6/spring-boot-cli-3.5.6-bin.zip

For manual installation, you need to use one of the following two archives −

  • spring-boot-cli-3.5.6-bin.zip

  • spring-boot-cli-3.5.6-bin.tar.gz

After the download, unpack the archive file and follow the steps given in the install.txt file. Note that it does not require any environment setup.

In Windows, go to the Spring Boot CLI bin directory in the command prompt and run the command spring -version to make sure spring CLI is installed correctly. After executing the command, you can see the spring CLI version as shown below −

D:\Projects\spring-3.5.6\bin&t; spring --version
Spring CLI v3.5.6
D:\Projects\spring-3.5.6\bin>

Create Welcome Message Web Application with Spring Boot CLI

D:\Projects\spring-3.5.6\bin> spring init --build maven -a test
Using service at https://start.spring.io
Content saved to 'test.zip'
D:\Projects\spring-3.5.6\bin>

Now you can check that a maven based spring boot project is created with following pom.xml

<?xml version="1.0" encoding="UTF-8"?>
   <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>3.5.6</version>
      <relativePath/> <!-- lookup parent from repository -->
   </parent>
   <groupId>com.example</groupId>
   <artifactId>test</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <name>demo</name>
   <description>Demo project for Spring Boot</description>
   <url/>
   <licenses>
      <license/>
   </licenses>
   <developers>
      <developer/>
   </developers>
   <scm>
      <connection/>
      <developerConnection/>
      <tag/>
      <url/>
   </scm>
   <properties>
      <java.version>17</java.version>
   </properties>
   <dependencies>
      <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter</artifactId>
      </dependency>
      <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-test</artifactId>
         <scope>test</scope>
      </dependency>
   </dependencies>
   <build>
      <plugins>
         <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
         </plugin>
      </plugins>
   </build>
</project>

Check the default java class which acts as a main application class. Update the content to the following −

package com.example.test;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {
   public static void main(String[] args) {
      SpringApplication.run(DemoApplication.class, args);
   }
   @RequestMapping("/")
   String home() {
      return "Hello World!";
   }
}

Let's add spring boot starter web dependency in pom.xml

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
</dependency>

Update DemoApplication.java with an end point to print "Welcome to Tutorialspoint!"

package com.example.test;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
public class DemoApplication {

   public static void main(String[] args) {
      SpringApplication.run(DemoApplication.class, args);
   }

   @GetMapping("/")
   String home() {
      return "Welcome to Tutorialspoint!";
   }
}

Now run the application by using the maven command mvn spring-boot:run as shown below −

E:\spring-3.5.6\bin\test>mvn spring-boot:run

Once you run the command, required dependencies will download automatically and it will start the application in Tomcat 8080 port as shown in the screenshot given below −

[INFO] Scanning for projects...
[INFO]
[INFO] --------------------------< com.example:test >--------------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] >>> spring-boot:3.5.6:run (default-cli) > test-compile @ test >>>
[INFO]
[INFO] --- resources:3.3.1:resources (default-resources) @ test ---
[INFO] Copying 1 resource from src\main\resources to target\classes
[INFO] Copying 0 resource from src\main\resources to target\classes
[INFO]
[INFO] --- compiler:3.14.0:compile (default-compile) @ test ---
[INFO] Recompiling the module because of added or removed source files.
[INFO] Compiling 1 source file with javac [debug parameters release 17] to target\classes
[INFO]
[INFO] --- resources:3.3.1:testResources (default-testResources) @ test ---
[INFO] skip non existing resourceDirectory E:\spring-3.5.6\bin\test\src\test\resources
[INFO]
[INFO] --- compiler:3.14.0:testCompile (default-testCompile) @ test ---
[INFO] Recompiling the module because of changed dependency.
[INFO] Compiling 1 source file with javac [debug parameters release 17] to target\test-classes
[INFO]
[INFO] <<< spring-boot:3.5.6:run (default-cli) < test-compile @ test <<<
[INFO]
[INFO]
[INFO] --- spring-boot:3.5.6:run (default-cli) @ test ---
Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-buildpack-platform/3.5.6/spring-boot-buildpack-platform-3.5.6.pom
...
[INFO] Attaching agents: []

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/

 :: Spring Boot ::                (v3.5.6)

2025-09-28T13:04:33.672+05:30  INFO 3216 --- [demo] [           main] com.example.test.DemoApplication         : Starting DemoApplication using Java 24.0.1 with PID 3216 (D:\Projects\spring-3.5.6\bin\test\target\classes started by mahes in D:\Projects\spring-3.5.6\bin\test)
2025-09-28T13:04:33.675+05:30  INFO 3216 --- [demo] [           main] com.example.test.DemoApplication         : No active profile set, falling back to 1 default profile: "default"
2025-09-28T13:04:34.231+05:30  INFO 3216 --- [demo] [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port 8080 (http)
2025-09-28T13:04:34.246+05:30  INFO 3216 --- [demo] [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2025-09-28T13:04:34.246+05:30  INFO 3216 --- [demo] [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.46]
2025-09-28T13:04:34.303+05:30  INFO 3216 --- [demo] [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2025-09-28T13:04:34.304+05:30  INFO 3216 --- [demo] [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 580 ms
2025-09-28T13:04:34.626+05:30  INFO 3216 --- [demo] [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port 8080 (http) with context path '/'
2025-09-28T13:04:34.632+05:30  INFO 3216 --- [demo] [           main] com.example.test.DemoApplication         : Started DemoApplication in 1.274 seconds (process running for 1.521)

Once Tomcat starts, go to the web browser and hit the URL http://localhost:8080/ and you can see the output as shown.

Hello Spring Boot
Advertisements