Bootstrapping a Spring Boot Web Application

Learn to create a Spring boot web application using Spring Intializr interface and with Maven or Gradle.

1. Pre-requisites

We can create the web application using Spring Initializr, download and import it into an IDE such as Eclipse. We will need the following to get started:

Alternatively, we can directly create the web application in the following IDEs using the Maven quickstart archetype.

2. Generated Artifacts

Let us assume we are creating the project using Spring Initializr using Maven to import dependencies and build the project.

Selected Configuration Options

2.1. Dependencies

The generated project’s parent is spring-boot-starter-parent.

	<relativePath/> <!-- lookup parent from repository -->

The pom.xml also contains the modules we imported. Each project has spring-boot-starter-test imported automatically.


2.2. Application Bootstrap Class and Test Class

The generated project source code also contains two Java files.

The first file is used to run the application with an embedded Tomcat server. This contains one of the essential annotations i.e., @SpringBootApplication. This annotation is a combination of three annotations:

  • @Configuration
  • @EnableAutoConfiguration
  • @ComponentScan
public class SpringBootStarterApplication {

    public static void main(String[] args) {, args);


The second file is for writing the JUnit tests.

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

class SpringBootStarterApplicationTests {

    void contextLoads() {


3. Hello World Mapping

The default-created application does not have any URL handler, so all the URLs will return 404 status. We need to create a URL mapping and its handler to test the application.

Create a class HelloWorldController and provide a method to handle root URL.

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

public class HelloWorldController {
    public String hello() {
        return "Hello World !!";

4. Running the Application

To run the application, run the main() method in the class SpringBootStarterApplication. This will start the embedded tomcat server and deploy the application into it.

By default, the application starts at port 8080 and the default context path is ‘/‘.

The Response in Browser

5. Customize the Defaults

There are some sensible defaults we can change to start customizing this application. Each configuration item can be changed using a property in file.

There is a long list of spring boot properties, we can customize.

server.port=8081   #Server port number

server.servlet.context-path=myapp   #Context path of the application

6. Conclusion

In this tutorial, we learned to create a spring boot application from scratch. Though we can create the application in the IDEs too, using the Spring Intializr interface is very much convenient.

The source code of the examples here is over on GitHub.

Leave a Comment