Spring Boot Tutorial

Last modified: July 11, 2017

This is a quickstart tutorial for Spring Boot. We will be building out a simple Spring Boot REST example from scratch using Maven.

Spring Boot Tutorial: Getting Started

This tutorial assumes you have Maven installed. If not, please install the latest stable version of Maven. To get started, create a new directory and cd into it. Run the following to create the basic Spring Boot app structure:

mkdir -p src/main/java/webapp

This creates the basic file structure for our Spring Boot project. Now lets add our pom.xml file to the root directory of the project. This file contains the configuration details behind your Maven build, including any required dependencies and plugins for the project. Once created, copy the following into the pom.xml file:


<?xml version="1.0" encoding="UTF-8"?>

This adds the required dependencies for Spring Boot as well as the Spring Boot Maven plugin.

Creating The REST Controller

To create a sample REST endpoint, we add a Java class with the Spring Boot REST controller annotations. Under the webapp directory, add a WebAppController.java.


package webapp;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;

public class WebAppController {

    public String mainPage() {
        return "Hello World";


This creates a basic REST endpoint defined by the @RequestMapping("/"). Notice how we define our route /. in the @RequestMapping annotation. We then simply return a string, "Hello World", to the browser.

Creating Spring Boot App

Under the webapp directory, create another java class Application.java.


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

public class Application {

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


This creates the launch script for our Spring Boot instance.

Running the App

Navigate to the root of the project and run the following maven command:

mvn clean package

This will build the Spring Boot project using Maven. Once complete, run:

java -jar target/hello-spring-boot-0.1.0.jar

This runs the executable jar file produced by the mvn clean package and stored under the /target directory.

You should see the local port printed in the console. Navigate to the localhost, such as localhost:8080, in the browser. If all went according to plan, you should see the worlds "Hello World" on the screen.


That's it. You've created a basic Spring Boot REST example and run a local instance of the app. You'll probably want to return more than just strings to the browser so remember that there are plenty of template engines for Spring (Thymeleaf) that make rendering client rich web apps a breeze.


Roopesh Kumariv
May 11, 2017
spring boot is super easy to set up. it definitely gives node.js/express a run for it's money. while traditional spring had a ton of boilerplate code none of us like, this simple set up makes SpringBoot better than node.js in my opinion, mainly because of all the benefits you get with using something that is Java based vs JavaScript based.
Bindui S.
April 7, 2017
um more please. this made spring boot an absolute breeze. thanks for just giving me the info and skipping (most of) the bs. can you please produce more stuff like this. i know tons of people looking to get into java and spring and this was a great tutorial.
Sam E.
March 22, 2017
the hard part is installing maven if you ask me :)
Terry Neumont
March 22, 2017
super fast tutorial. it works!

You might also like: