How to Quickly Bootstrap a Spring Boot Project: A Step‑by‑Step Guide

This tutorial walks you through setting up a Spring Boot 2.1.3 project using Maven, covering environment prerequisites, two creation methods (Spring Initializr and IntelliJ IDEA plugin), project structure, configuration, essential dependencies, a HelloWorld REST controller, unit testing, and important deployment tips.

Senior Brother's Insights
Senior Brother's Insights
Senior Brother's Insights
How to Quickly Bootstrap a Spring Boot Project: A Step‑by‑Step Guide

Overview

Spring Boot 2.1.3 provides rapid scaffolding for Java web applications. It uses Maven for build and embeds Tomcat, allowing the application to be started with java -jar.

Environment Requirements

JDK 8+ and Maven 3.3+ are required. Spring Boot version 2.1.3.RELEASE is used.

Project Creation – Spring Initializr

Generate a Maven‑based Java project at https://start.spring.io/ with the following settings:

Project: Maven

Language: Java

Spring Boot: 2.1.3.RELEASE

GroupId / ArtifactId: your Maven coordinates

Packaging: Jar (or War if an external container is needed)

Java version: 8

Dependency: Web (adds spring-boot-starter-web)

Click “Generate Project”, unzip the archive and open it as a Maven project in your IDE.

Project Creation – IntelliJ IDEA

Install the Spring Boot plugin, then choose File → New → Project → Spring Initializr. The wizard uses the same URL as above. Provide the same metadata, select the “Web” starter, and finish. IDEA will import the generated Maven project automatically.

Directory Layout

The standard Maven layout is produced: src/main/java – Java source (application class, controllers, services) src/main/resources – Configuration files such as application.properties and static assets src/test/java – Unit‑test sources

Configuration

Spring Boot replaces XML configuration with application.properties. The embedded Tomcat listens on port 8080 by default; change the port with:

server.port=8081

pom.xml

<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 http://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>2.1.3.RELEASE</version>
  </parent>

  <groupId>com.example</groupId>
  <artifactId>demo</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <properties>
    <java.version>1.8</java.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</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>

HelloWorld REST Controller

package com.example.demo.controller;

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

@RestController
public class HelloWorldController {

    @RequestMapping("/hello")
    public String hello() {
        return "hello world!";
    }
}

Run the generated DemoApplication class (the main method created by Spring Initializr) and access http://localhost:8080/hello. The response should be hello world!.

Unit Test

package com.example.demo;

import com.example.demo.controller.HelloWorldController;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;

import static org.hamcrest.core.IsEqual.equalTo;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@RunWith(SpringRunner.class)
@SpringBootTest
public class DemoApplicationTests {

    private MockMvc mockMvc;

    @Before
    public void init() {
        mockMvc = MockMvcBuilders.standaloneSetup(new HelloWorldController()).build();
    }

    @Test
    public void testHello() throws Exception {
        mockMvc.perform(MockMvcRequestBuilders.get("/hello")
                .accept(MediaType.APPLICATION_JSON))
                .andExpect(status().isOk())
                .andExpect(content().string(equalTo("hello world!")));
    }
}

Important Notes

Place application code in the same package (or a sub‑package) as the class containing the main method; otherwise component scanning will miss the beans.

If the project contains additional classes with a main method, comment them out or convert them to tests, because Spring Boot expects a single entry point when the jar is executed.

Source Code

Full example repository:

https://github.com/secbr/springboot-all/tree/master/demo
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavamavenSpring BootTutorialIDEArest
Senior Brother's Insights
Written by

Senior Brother's Insights

A public account focused on workplace, career growth, team management, and self-improvement. The author is the writer of books including 'SpringBoot Technology Insider' and 'Drools 8 Rule Engine: Core Technology and Practice'.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.