Developing a simple web application with Spring Boot

spring boot tutorial

Spring is an open source JAVA framework which is widely popular amongst web development as it helps in creating high performing, easily testable and reusable code. Spring Boot is provides the power of Spring with minimal configurations as it covers most of the configurations on it’s own but if one wants custom configurations then that can also be done by extending desired configuration class. I won’t go deep into Spring tutorial rather will focus on developing a web application with Spring Boot.

Following are the prerequisites of the tutorial:

First let’s create a project using the New Maven Project wizard in STS

  • Step 1:
  • Step 2:
  • Step 3:

This will create our project and basic required folders and files including the which will contain all the maven configuration of our project.

As you can see, I’ve added as parent maven dependency.

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.4</version>
<type>pom</type>
</dependency>

This helps in setting up versions of other child dependencies and makes our project a child project of this parent. So as I’m developing a web application so a new dependency needs to be added to get all the required dependencies to create a spring web application.

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

The final will look something like this:

Here, I’ve added dependency without mentioning tag as the version of this dependency has been taken care of by parent . So my will look like this.

Now let’s create a JAVA class which will be the initializing point of our application and as this will be our main class so need to create method in the class.

The method will make sure this application can stand-alone. So, I’ve added the code inside the main method which tells spring that this is a spring application, to create and start a servlet container, and host this application.

Adding the annotation and the method makes this application stand-alone. This is it! A very simple spring boot application is ready to run. Now, after running the application as spring boot, you’ll notice the following in the console.

This means our application has started in tomcat server on 8080 port which is a default port for tomcat. Now let’s hit the url and you’ll notice below screen.

This doesn’t mean our application has failed rather this mean our application is up & running but this error is coming due to missing page while accessing the url and so it tried to find page on path which is again missing as I’ve not created any webpage yet so being redirected to this fallback page.

Download the project from GitHub: prafullsranjan/simple-spring-boot (github.com)