---
title: "Introduction to Spring Boot Framework"
lang: "en"
author: "Mohammad Abu Mattar"
canonical: https://mkabumattar.com/post/introduction-to-spring-boot-framework
---

![Blog post image for Introduction to Spring Boot Framework - Many developers use the Spring Boot framework to build web apps and microservices. It's built on top of the Spring Framework and adds a number of conveniences that make it a popular choice. This post covers what Spring Boot is, why it's useful, and how to create a basic Spring Boot application.](/_astro/hero.DBZ88JEm_1dnMjV.webp)

[Home](/)›[Blog](/blog)›[All Categories](/blog/categories)›[Java](/blog/categories/java)

Blog

[Prev in JavaHow to Deploy a Spring Boot Application to AWS CloudFormation](/blog/post/how-to-deploy-a-spring-boot-application-to-aws-cloudformation)

[Java](/blog/categories/java)[Spring Framework](/blog/categories/spring-framework)[Backend Development](/blog/categories/backend-development)[Microservices](/blog/categories/microservices)

# Introduction to Spring Boot Framework

[Mohammad Abu Mattar](/authors/mohammad-abu-mattar)Published: 15 Jan 202306 Mins read10 Mins listen

[Markdown for AI(opens in a new tab)](/post/introduction-to-spring-boot-framework/index.md "Open the plain-Markdown version of this page, for pasting into an AI tool")

TL;DR

Many developers use the Spring Boot framework to build web apps and microservices. It's built on top of the Spring Framework and adds a number of conveniences that make it a popular choice. This post covers what Spring Boot is, why it's useful, and how to create a basic Spring Boot application.

Series

[Spring Boot on AWS](/series/spring-boot-on-aws)1/2

[NextHow to Deploy a Spring Boot Application to AWS CloudFormation](/blog/post/how-to-deploy-a-spring-boot-application-to-aws-cloudformation)

All posts in this series (2)

Blog2

1.  [Introduction to Spring Boot FrameworkYou are here](/blog/post/introduction-to-spring-boot-framework)
2.  [How to Deploy a Spring Boot Application to AWS CloudFormation](/blog/post/how-to-deploy-a-spring-boot-application-to-aws-cloudformation)

### Introduction to Spring Boot Framework

Contents

[Introduction](#introduction)[What is Spring Boot?](#what-is-spring-boot)[Why Spring Boot?](#why-spring-boot)[Spring Boot features](#spring-boot-features)[Easy setup and automatic configuration](#easy-setup-and-automatic-configuration)[Stand-alone applications](#stand-alone-applications)[Web development](#web-development)[Testing and deployment](#testing-and-deployment)[Build a simple Spring Boot application](#build-a-simple-spring-boot-application)[Create a Spring Boot project](#create-a-spring-boot-project)[Create a controller](#create-a-controller)[Run the application](#run-the-application)[Test the application](#test-the-application)[Conclusion](#conclusion)[References](#references)

## [Introduction](#introduction)

Many developers use the Spring Boot framework to build web apps and microservices. It’s built on top of the Spring Framework and adds a number of conveniences that make it a popular choice for developers. This post covers what Spring Boot is, why it’s useful, and how to create a basic Spring Boot application.

## [What is Spring Boot?](#what-is-spring-boot)

Spring Boot lets you build standalone, production-ready apps quickly. It ships capabilities you can add to an application in a few lines, including security, data access, and web services. It also configures itself from the dependencies present in the project, so there is no manual configuration to do.

## [Why Spring Boot?](#why-spring-boot)

Spring Boot is a common choice for web apps and microservices because it is easy to use and covers a lot of ground. Developers like the range of capabilities and the fact that it configures itself. Its support for testing and deployment also makes it a strong and trustworthy framework for creating web applications.

## [Spring Boot features](#spring-boot-features)

### [Easy setup and automatic configuration](#easy-setup-and-automatic-configuration)

One of Spring Boot’s main advantages is that it configures itself from the dependencies present in the project. Developers no longer have to set the program up by hand, which cuts down on the time and effort needed to get an application up and running.

### [Stand-alone applications](#stand-alone-applications)

Another significant benefit is how easy it is to create and run standalone apps. The Spring Boot CLI is what makes this possible: you can construct a new application by executing a single command.

### [Web development](#web-development)

For creating web applications, Spring Boot supports RESTful web services, web sockets, and data validation, among other things. It also interfaces with a variety of well-known web development tools, like Mustache, FreeMarker, and Thymeleaf, which makes it simple to build dynamic, interactive web pages.

### [Testing and deployment](#testing-and-deployment)

Spring Boot also offers features for testing and deploying apps. The framework supports unit testing tools like JUnit and Mockito. Once an application has been launched, Spring Boot gives you tools for administering and monitoring it, including metrics and health checks.

## [Build a simple Spring Boot application](#build-a-simple-spring-boot-application)

### [Create a Spring Boot project](#create-a-spring-boot-project)

The first step to building a Spring Boot application is to create a new project. This can be done using the Spring Initializer website ([https://start.spring.io](https://start.spring.io)) or the Spring Boot CLI.

Terminal window

```
1curl https://start.spring.io/starter.tgz \2  -d baseDir=spring-boot-web \3  -d version=0.0.1-SNAPSHOT \4  -d type=maven-project \5  -d language=java \6  -d bootVersion=2.4.2 \7  -d groupId=io.github.mkabumattar \8  -d artifactId=spring-boot-web \9  -d name=spring-boot-web \10  -d packageName=io.github.mkabumattar.springbootweb \11  -d dependencies=web \12  -d packaging=jar \13  -d javaVersion=11 \14  -d dependencies=web \15  | tar -xzvf -
```

This command uses `curl` to download a `starter.tgz` file from the Spring Initializer website, with the specified options passed in as query parameters. The options include:

-   `baseDir`, which sets the base directory for the project
-   `version`, which sets the version of the project
-   `type`, which specifies that the project is a Maven project
-   `language`, which sets the programming language of the project as Java
-   `bootVersion`, which sets the version of Spring Boot to use in the project
-   `groupId`, which sets the Maven groupId for the project
-   `artifactId`, which sets the Maven artifactId for the project
-   `name`, which sets the name of the project
-   `packageName`, which sets the package name for the project
-   `dependencies`, which sets the dependencies needed for the project. In this case, it is web
-   `packaging`, which sets the packaging format as a JAR file
-   `javaVersion`, which sets the Java version to be used in the project

The output of this command is then piped to the `tar` command, which extracts the downloaded file. The options passed to `tar` are `xzvf -`, which mean extract the archive, gzip compressed, verbosely, reading from stdin.

This command will download and extract a new Spring Boot project with the specified options. The project will have a directory structure that is typical of a Maven project, and it will have the Spring Web dependency already set up and configured.

### [Create a controller](#create-a-controller)

The next step is to create a controller to handle requests for the application. A controller is a Java class that manages incoming HTTP requests and provides the proper response. Here is a simple controller that sends back the JSON object “Hello World”:

src/main/java/io/github/mkabumattar/springbootweb/controllers/HelloWorldController.java

```
1package io.github.mkabumattar.springbootweb.controllers;2
3import org.springframework.web.bind.annotation.GetMapping;4import org.springframework.web.bind.annotation.RestController;5
6import java.util.HashMap;7import java.util.Map;8
9@RestController10public class HelloWorldController {11
12    @GetMapping("/hello")13    public Map<String, String> sayHello() {14        Map<String, String> response = new HashMap<>();15        response.put("message", "Hello World!");16        return response;17    }18}
```

The `@GetMapping` annotation tells Spring that this method should handle GET requests to the `/hello` endpoint, and the `@RestController` annotation tells Spring to treat this class as a REST controller. The method returns a simple map with a single key-value pair: the key “message” and the value “Hello World”.

This is a simple example of a Spring Boot controller, but it can be extended to handle more complicated routes, accept various requests, and deliver more sophisticated results.

### [Run the application](#run-the-application)

Once the project has been constructed and a controller has been added, you can launch the application from the main method in the generated `SpringBootWebApplication.java` file, or with the `spring-boot:run` command if you are using the Spring Boot CLI.

You can also build the program and launch the jar file it produces. Use `mvn clean install` to build a Spring Boot application with Maven, and then `java -jar target/your-jar-file.jar` to launch the created jar file.

When the application is up and running, it is reachable at `http://localhost:8080` by default. To test it, open `http://localhost:8080/hello` in the browser, or send a GET request to that endpoint using a program like curl or postman. The answer should be a json object with a single key-value pair: the key “message” and the value “Hello World”.

You can also select a different port number: set the `server.port` property in the `application.properties` file, or add `--server.port=<your-port-number>` to the command line arguments when executing the application.

Spring Boot automatically starts an embedded Tomcat, Jetty, or Undertow server when you launch the application, to process web requests and run your application.

### [Test the application](#test-the-application)

After launching the Spring Boot application, you can test it to make sure everything is operating as it should. One method is to make a request to the endpoints specified in your controllers, using a web browser or a tool like `curl` or `postman`, and look at what comes back.

In the preceding example we created a `HelloWorldController` that handles the `/hello` endpoint. So you can test it by visiting the URL `http://localhost:8080/hello` in a web browser, or by sending a GET request to that endpoint using a tool like `curl` or `postman`. The response should be a json object with a single key-value pair: the key “message” and the value “Hello World”.

Unit tests, written with a testing framework like JUnit or TestNG, are another approach. Those tests can cover the controllers, services, and repository classes, among other components of the application. Spring Boot offers a variety of annotations and services that make writing tests for a Spring Boot application simple.

JUnit is a well-liked testing framework for Java applications, and one option for testing a Spring Boot application. With JUnit you can write unit tests for specific application parts, such as the controllers, services, and repository classes.

To use JUnit in a Spring Boot application that uses Maven as a build tool, you must include the JUnit dependency in the `pom.xml` file.

Here is an example of how you can add JUnit to your `pom.xml` file:

pom.xml

```
1<dependency>2    <groupId>junit</groupId>3    <artifactId>junit</artifactId>4    <version>4.13.2</version>5    <scope>test</scope>6</dependency>
```

Here is an example of how you can use JUnit to test a simple REST controller:

src/test/java/io/github/mkabumattar/springbootweb/controllers/HelloWorldControllerTest.java

```
1package io.github.mkabumattar.springbootweb.controllers;2
3import static org.hamcrest.Matchers.is;4import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;5import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;6import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;7
8import org.junit.Before;9import org.junit.Test;10import org.junit.runner.RunWith;11import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;12import org.springframework.boot.test.context.SpringBootTest;13import org.springframework.test.context.junit4.SpringRunner;14import org.springframework.test.web.servlet.MockMvc;15import org.springframework.test.web.servlet.setup.MockMvcBuilders;16
17@RunWith(SpringRunner.class)18@SpringBootTest19@AutoConfigureMockMvc20public class HelloWorldControllerTest {21    private MockMvc mockMvc;22
23    @Before24    public void setUp() {25        mockMvc = MockMvcBuilders.standaloneSetup(new HelloWorldController()).build();26    }27
28    @Test29    public void testSayHello() throws Exception {30        mockMvc.perform(get("/hello"))31                .andExpect(status().isOk())32                .andExpect(jsonPath("$.message", is("Hello World!")));33    }34}
```

## [Conclusion](#conclusion)

Spring Boot is an effective framework for creating Java web apps. Automatic setup, stand-alone applications, web development, testing, and deployment are just a few of the capabilities it offers, and together they make a Spring-based application simple to set up, configure, and execute.

We have covered the fundamentals of Spring Boot in this post, along with how to construct a simple Spring Boot application. We went through creating a project, adding a Spring Web dependency, adding a controller, running the application, and testing it. We also looked at how to test the application using MockMvc and JUnit.

Spring Boot is a solid option for building web apps: it’s simple to get started with and includes a lot of functionality out of the box. Its documentation and community make it easier to find tools and help while building and shipping your application.

This only covers the basics of what Spring Boot can do. As you use it more, you’ll get familiar with more of its capabilities and learn how to use them to build more complex applications.

## [References](#references)

Here are some references that you can use to learn more about Spring Boot:

-   [Spring Boot Official Website](https://spring.io/projects/spring-boot)
-   [Spring Boot Reference Guide (Current Version)](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/)
-   [Spring Initializr](https://start.spring.io/) - Tool for bootstrapping Spring Boot projects.
-   [Spring Framework Documentation](https://spring.io/docs)
-   [Building a RESTful Web Service with Spring Boot](https://spring.io/guides/gs/rest-service/) - Official Spring Guide.
-   [Spring Boot GitHub Repository](https://github.com/spring-projects/spring-boot)
-   [Baeldung - Spring Boot Tutorials](https://www.baeldung.com/spring-boot) (Popular community resource)
-   [Maven Official Website](https://maven.apache.org/)
-   [JUnit 5 User Guide](https://junit.org/junit5/docs/current/user-guide/)
-   [Spring Boot Testing](https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.testing) - Official documentation on testing.
-   [What is Spring Boot? - spring.io](https://spring.io/guides/gs/spring-boot/#what-is-spring-boot)
-   [Spring Boot CLI Documentation](https://docs.spring.io/spring-boot/docs/current/reference/html/cli.html)
-   [Thymeleaf Documentation (for web development with Spring Boot)](https://www.thymeleaf.org/documentation.html)
-   [MockMvc - Spring Framework Documentation](https://docs.spring.io/spring-framework/docs/current/reference/html/testing.html#spring-mvc-test-server)

Was this useful?

## Tags

[#Spring Boot](/blog/tags/spring-boot)[#Java Development](/blog/tags/java-development)[#Spring Framework](/blog/tags/spring-framework)[#Microservices](/blog/tags/microservices)[#REST API](/blog/tags/rest-api)[#Web Development](/blog/tags/web-development)[#Spring Initializr](/blog/tags/spring-initializr)[#Maven](/blog/tags/maven)[#JUnit](/blog/tags/junit)

## Share

[Facebook](https://facebook.com/sharer/sharer.php?u=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fintroduction-to-spring-boot-framework "Share on Facebook")[Twitter](https://twitter.com/intent/tweet/?text=Introduction%20to%20Spring%20Boot%20Framework&url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fintroduction-to-spring-boot-framework "Share on Twitter")[LinkedIn](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fintroduction-to-spring-boot-framework&title=Introduction%20to%20Spring%20Boot%20Framework&summary=Many%20developers%20use%20the%20Spring%20Boot%20framework%20to%20build%20web%20apps%20and%20microservices.%20It's%20built%20on%20top%20of%20the%20Spring%20Framework%20and%20adds%20a%20number%20of%20conveniences%20that%20make%20it%20a%20popular%20choice.%20This%20post%20covers%20what%20Spring%20Boot%20is%2C%20why%20it's%20useful%2C%20and%20how%20to%20create%20a%20basic%20Spring%20Boot%20application.&source=https://mkabumattar.com "Share on LinkedIn")[WhatsApp](https://wa.me/?text=Introduction%20to%20Spring%20Boot%20Framework%20https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fintroduction-to-spring-boot-framework "Share on WhatsApp")[Telegram](https://t.me/share/url?url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fintroduction-to-spring-boot-framework&text=Introduction%20to%20Spring%20Boot%20Framework "Share on Telegram")[Reddit](https://www.reddit.com/submit?url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fintroduction-to-spring-boot-framework&title=Introduction%20to%20Spring%20Boot%20Framework "Share on Reddit")[Hacker News](http://news.ycombinator.com/submitlink?u=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fintroduction-to-spring-boot-framework&t=Introduction%20to%20Spring%20Boot%20Framework "Share on Hacker News")[Pinterest](https://pinterest.com/pin/create/button/?url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fintroduction-to-spring-boot-framework&media=&description=Many%20developers%20use%20the%20Spring%20Boot%20framework%20to%20build%20web%20apps%20and%20microservices.%20It's%20built%20on%20top%20of%20the%20Spring%20Framework%20and%20adds%20a%20number%20of%20conveniences%20that%20make%20it%20a%20popular%20choice.%20This%20post%20covers%20what%20Spring%20Boot%20is%2C%20why%20it's%20useful%2C%20and%20how%20to%20create%20a%20basic%20Spring%20Boot%20application. "Share on Pinterest")[Email](<mailto:?subject=Introduction%20to%20Spring%20Boot%20Framework&body=Check out this article: https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fintroduction-to-spring-boot-framework>)

## Comments

## You might also enjoy

More posts on similar topics

[![How to Deploy a Spring Boot Application to AWS CloudFormation](/_astro/hero.C8XnJRc3_Z1OiL51.webp)](/blog/post/how-to-deploy-a-spring-boot-application-to-aws-cloudformation)

## [How to Deploy a Spring Boot Application to AWS CloudFormation](/blog/post/how-to-deploy-a-spring-boot-application-to-aws-cloudformation)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [Spring Boot](/blog/categories/spring-boot)
-   [CloudFormation](/blog/categories/cloudformation)
-   [DevOps](/blog/categories/devops)
-   [Java](/blog/categories/java)

Introduction Deploying a Spring Boot application to the cloud can provide many benefits such as scalability and easy management. AWS CloudFormation is a service that allows for the creation and ma

[#AWS CloudFormation](/blog/tags/aws-cloudformation)[#Spring Boot Deployment](/blog/tags/spring-boot-deployment)[#Java on AWS](/blog/tags/java-on-aws)+5 tags

[read more](/blog/post/how-to-deploy-a-spring-boot-application-to-aws-cloudformation)

[![REST API vs RESTful API: Architecture and Constraints Explained](/_astro/hero.D7ffsaFk_ZsjslT.webp)](/blog/post/rest-api-vs-restful-api-architecture-and-constraints-explained)

## [REST API vs RESTful API: Architecture and Constraints Explained](/blog/post/rest-api-vs-restful-api-architecture-and-constraints-explained)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [API Development](/blog/categories/api-development)
-   [Web Architecture](/blog/categories/web-architecture)
-   [Software Engineering](/blog/categories/software-engineering)
-   [Backend Development](/blog/categories/backend-development)

Introduction REST API and RESTful API get used interchangeably, but they aren't quite the same thing. This post covers the difference, REST's constraints, and what they mean for how you design an

[#REST API](/blog/tags/rest-api)[#RESTful API](/blog/tags/restful-api)[#API Design Principles](/blog/tags/api-design-principles)+6 tags

[read more](/blog/post/rest-api-vs-restful-api-architecture-and-constraints-explained)

[![The Real Talk on Microservices vs. Monoliths](/_astro/hero.CCnE1S4X_Z1X4cS2.webp)](/blog/post/0076-the-dark-side-of-microservices-when-to-avoid-them)

## [The Real Talk on Microservices vs. Monoliths](/blog/post/0076-the-dark-side-of-microservices-when-to-avoid-them)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [Software Architecture](/blog/categories/software-architecture)
-   [Microservices](/blog/categories/microservices)
-   [Monoliths](/blog/categories/monoliths)
-   [System Design](/blog/categories/system-design)

The tricky side of tiny boxes: when smaller isn't always better So, microservices, right? They're all the rage in the software world these days. Everyone's buzzing about how they make things super

[#Microservices](/blog/tags/microservices)[#Monoliths](/blog/tags/monoliths)[#Software Architecture](/blog/tags/software-architecture)+7 tags

[read more](/blog/post/0076-the-dark-side-of-microservices-when-to-avoid-them)

[![The ORM Dilemma: To Use or Not to Use](/_astro/hero.DwvXnAvK_Zoy6I4.webp)](/blog/post/why-not-to-use-orm-in-nodejs)

## [The ORM Dilemma: To Use or Not to Use](/blog/post/why-not-to-use-orm-in-nodejs)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [Backend Development](/blog/categories/backend-development)
-   [Node.js](/blog/categories/nodejs)
-   [Database Management](/blog/categories/database-management)
-   [Software Architecture](/blog/categories/software-architecture)
-   [TypeScript](/blog/categories/typescript)

Introduction Some decisions shape a project more than others. One that keeps coming back is whether to use an Object-Relational Mapping (ORM) tool for database interactions. Should you skip an ORM

[#ORM](/blog/tags/orm)[#Node.js](/blog/tags/nodejs)[#TypeScript](/blog/tags/typescript)+8 tags

[read more](/blog/post/why-not-to-use-orm-in-nodejs)

[![What is DevOps?](/_astro/hero.1og2dXaB_Z19nggu.webp)](/blog/post/what-is-devops)

## [What is DevOps?](/blog/post/what-is-devops)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [DevOps](/blog/categories/devops)
-   [Software Development](/blog/categories/software-development)
-   [IT Operations](/blog/categories/it-operations)
-   [Agile](/blog/categories/agile)

What is DevOps, and why is it important? The name "DevOps" combines the terms "development" and "operations," but it covers a far broader range of principles and procedures than those two terms do

[#DevOps Culture](/blog/tags/devops-culture)[#CI/CD](/blog/tags/cicd)[#Automation](/blog/tags/automation)+6 tags

[read more](/blog/post/what-is-devops)

[![Caching Strategies with Redis in Node.js and TypeScript](/_astro/hero.KUKAT2kl_Z1Ypf5o.webp)](/blog/post/caching-strategies-with-redis-in-node-js-and-typescript)

## [Caching Strategies with Redis in Node.js and TypeScript](/blog/post/caching-strategies-with-redis-in-node-js-and-typescript)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [Backend Development](/blog/categories/backend-development)
-   [Caching](/blog/categories/caching)
-   [Performance Optimization](/blog/categories/performance-optimization)
-   [Node.js](/blog/categories/nodejs)
-   [Redis](/blog/categories/redis)
-   [TypeScript](/blog/categories/typescript)

Introduction Optimizing application performance is an ongoing job, and caching is one of the most effective ways to do it. Redis, a fast in-memory data store, is a common choice for caching in Nod

[#Redis Cache](/blog/tags/redis-cache)[#Caching Strategies](/blog/tags/caching-strategies)[#Node.js Performance](/blog/tags/nodejs-performance)+8 tags

[read more](/blog/post/caching-strategies-with-redis-in-node-js-and-typescript)

6 related posts
