Java Spring Boot — Intro. First of all, Spring Boot consists of…
Tags: Java, Spring Boot, Java Spring Boot

Creating a Spring Boot Project

There are several approaches we can use to build a Spring Boot Application. The first one I will explain here is by creating a maven project using Eclipse IDE.

When we open the Eclipse IDE look at the Project Explorer tab and choose Create a Maven project. Maven is build and dependency management tool used primary for Java projects.

After that, we need to fill in some details regarding the project we want to build as shown below. Group Id is like a package name of my project, and Artifact Id is my project name. You can fill in the fields with anything suitable for you and just leave the Parent Project section blank.

Right after you click the Finish button, Eclipse will be creating a blank maven project for us. If there is no problem, Eclipse will show us the following layout.

At the Project Explorer tab, now we can see Eclipse already downloaded some dependency we need to create a maven project as well as created the project template for us.

Pay attention to the pom.xml file. This file defines the project structure and the dependency our project needs to make it run. Moreover, this file is the one we have to configure first to make our project become a Spring Boot project.

Until now, we have already made a simple maven project. What we have done so far has nothing to do with Spring Boot. To make it a Spring Boot project, there are a bunch of steps we have to follow and it starts with this pom.xml file.

First, add the following lines in pom.xml.

These lines tell Maven that the project we are creating is a child project of the spring-boot-starter-parent project since we define it in the parent tag. Parent and child project is one of the Maven features that allow us to make one project, and make another project as it’s child project that inherits all the feature it has. Therefore, when we define spring-boot-starter-parent as our parent project, this project will inherit all of it’s features and behavior. Otherwise, now we already make our project a Spring Boot project.

The next step is adding all the dependency we need. To do this, add the dependencies tag as shown below, then we can add every dependency we need in the dependency tag.

What I have just done is I add the spring-boot-starter-web dependency since I wanna build a web service application and Maven will download all the jar files related to that dependency. We can see it in the Project Explorer tab, Maven already create the Maven Dependencies folder for us.

Sometimes we might encounter an error marked with a red sign on our project name icon like above or on the Markers tab below.

To solve the error we only need to update the project. Right click on our project name, go to Maven then choose Update Project.

The red mark should now be gone.

If we look into the Project Explorer tab, we will find in my case now by default Maven use JRE version 1.5, and it is a little bit ancient now. I will update it to version 1.8 by the following code. Eventually this is the full pom.xml file.

Now in order to make our project runnable, we need to do some other steps. What I am gonna do now is create a simple java class. Right click on our main java package, and create a new Class.

Here I already create a new java class named Application. We will use this class as the main class containing the main function which will be run.

Remember that the spring boot application will give us a runnable stand-alone application that we can just run like any other java program. This is already done by annotating the class containing the main method by using @SpringBootApplication annotation.