Spring Boot: A Quick Start

DZone 's Guide to

Spring Boot: A Quick Start

Interested in giving Spring Boot a try? This guide provides a set of simple steps, commands, and annotations that will get a web app up and running quickly.

· Java Zone ·
Free Resource

In this article, we will create a simple Spring Boot application which will run on embedded Apache Tomcat.

What Is Spring Boot?

Spring Boot helps in creating stand-alone, production-grade application easily with minimum fuss. It is the opinionated view of Spring framework and other third party libraries which believes in convenient configuration based setup.

Let's start building Spring Boot Application.

Adding Dependencies in pom.xml

We will first add spring-boot-starter-parent as parent of our maven based project.


The benefit of adding spring-boot-starter-parent is that version managing of dependency is easy. You can omit the required version on the dependency. It will pick the one configured in the parent pom or from starters pom. Also, it conveniently setup the build related configurations as well.

Adding the Spring-Boot-Starter-Web Dependency

This will configure/add all the required dependencies for the spring-web module.


Writing the App Class

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

indicates that class is a configuration class and also triggers the auto-configuration through @EnableAutoConfiguration and component scanning through the @ComponentScan annotation in it.


It enables the auto-configuration of Spring Application Context. It attempts to configure your application as per the classpath dependencies that you have added.

In the main() of the App class, we have delegated the call to the run() method of SpringApplication. SpringApplication will bootstrap and auto-configure our application and, in our case, will start the embedded Tomcat server. In the run method, we have passed App.class as an argument, which tells Spring that this is our primary Spring component (helps in bootstrapping).

Writing HelloGbController

 public class HelloGbController { 
    public String helloGb() { 
    return "Gaurav Bytes says, \"Hello There!!!\""; 

I have used two annotations — @RestController and @GetMapping. You can read more on new annotations introduced by Spring here.

@RestController signifies that this class is a web @Controller and Spring will consider it to handle incoming web requests.

Running the Application

You can use the maven command mvn spring-boot:run to run it as a Spring Boot application, and when you hit the localhost:8080, you will see the below web page.

You need to add the spring-boot-maven-plugin plugin to your build configuration in your pom.xml, then you can create a Jar with the maven command mvn repackage and simply run it as a JAR with the command java -jar spring-boot-quickstart-0.0.1-SNAPSHOT.jar.


This is how you can build a simple Spring Boot application. I hope you find this post helpful. You can download the example code from GitHub.

java, spring annotations, spring boot, tutorial, web app development

Published at DZone with permission of Gaurav Rai Mazra , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}