There is lot of material on the web to explain what spring boot is and why we need to use it, i’m just a newbie in spring boot. This series is my attempt to help learn springboot and code some practical use cases which might help others to learn and get hands on
You have to know the following before you start creating your spring boot project.
- Which version of java do you prefer or is supported in your environments
- Is there a version of spring boot recommended by your organization or you can choose the latest stable one
- Which build automation ( Maven or Gradle ) does your organization prefer to use?
- What are the dependencies needed for your project? you will actually be able to get to know about your dependencies based on the architecture diagram or design for your project. Some of the questions to ask yourself are
- Will you be exposing web services? REST or SOAP?
- Will you need to connect to any database to store or retrieve data? like MySQL or Oracle DB or MongoDB or any other SQL or NoSQL database.
- Do you want to use JDBC or JPA for working with databases
- Do you have any security requirements?like oAuth, spring security, LDAP etc
- Do you have any connectivity with queues like RabbitMQ, Kafka etc
- Do you need any specific cloud needs like Azure, AWS , GCP or Pivotal Cloud?
- Do you have any specific logging requirements?
- There are lot more categories of dependencies which you can explore yourself on the spring initializr website.
Now Assuming we kind of have answered fairly all the above questions. And you need not worry if you missed out any dependencies, it can always be added in the later stage during development
Steps to create the Spring Boot project
- Go to https://start.spring.io/ and it will look something like this

- Select the Build Automation ( Maven or gradle ). I have chosen Maven
- Select the Language of programming ( Java or Kotlin or Groovy ) . I have chosen Java
- Select the Spring boot version that you want. I have selected 2.3.3 version. 2.4.0 is the new upcoming version. I would prefer to select the last stable version if we don’t know which one is recommended
- Next step would be to provide a group name. I have given
com.springboot.demo
and a artifact name. The name of your project goes into the artifact. You can also edit your package name and description as per your needs

- Next select how you want to generate the project, as a JAR or WAR. i would prefer JAR since i will be importing this project in an IDE like eclipse or intellij
- You would select the version of java. I would go with Java 11 for now.
Now lets look at how to add dependencies. I will just add web dependencies since we will just create a simple REST service with this demo project
- Click on the add dependencies button

- Now you will see the list of dependencies. you can scroll or type in the dependency name, eg: i started typing web and selected Spring Web dependency as shown below.

- Second dependency i will add is the spring boot devtools as shown below. this will help to live reload our project when we make changes in our IDE.

- Now just verify all the configurations you selected again and to generate the project you can click on Generate button in the bottom of the spring initializr page

This will download a springbootdemo.zip
file and when you unzip it it will provide you the project with following files ready to use.

Here is the content of pom.xml file
<?xml version="1.0" encoding="UTF-8"?>
<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 https://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.6.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.springboot.demo</groupId>
<artifactId>SpringBootDemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>SpringBootDemo</name>
<description>Demo project for Spring Boot webservices</description>
<properties>
<java.version>11</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-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</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>
Congratulations, you have just created a spring boot project. You can import this into the IDE of your choice and code and build the features that were required by your project.
Importing the spring boot project into Eclipse
1. Download Eclipse
You can download the eclipse from the website here https://www.eclipse.org/downloads/packages/
See more instructions for how to install Eclipse IDE on Ubuntu
I will usually prefer to download the Eclipse IDE for enterprise java Developers. Depending on the Operating System and the processor type you can download for windows, linux or Mac and 32bit or 64bit from the eclipse site.

- There is not much setup required for Eclipse, you get a .zip file when downloaded. You just have to unzip it and start using. Below is the folder structure that is inside the eclipse zip file. clicking on eclipse.exe will open up the eclipse IDE

- You can enter your workspace name and choose the path and click on launch

2. Importing the spring boot project
Once your eclipse IDE is open,
- Click on File →Import , which will open up an import window

- Type in Maven and select “Existing Maven Projects” and click Next

- Now click on browse button and navigate to the Spring boot project location and select the folder where we unzipped the SpringBootDemo project. Once you select and click ok, the window should identify the pom.xml file and show as below. Click Finish

- Give it couple of minutes to import all the required maven dependencies. You can see the progress bar in the bottom left corner of eclipse as shown below. Wait for it to complete

- Once its imported, you will be the project structure as shown below in your project explorer

Following are the three important files or paths that you will need most of the time. We will go through the details of each in other posts
- The src/main/java path will contain java class files. There will already be a default <ProjectName>Application.java file which is your springboot starting file
- application.properties inside the src/main/resources path where you will be able to configure the application properties like application name, ports db urls etc
- pom.xml file which will be the file where you will configure all maven dependencies that are needed for your project.
3. Running the Spring boot project
You can right click the project or the SpringBootDemoApplication.java file and run as java application or Spring boot application

And you will see the spring boot application starting in console of your eclipse. As shown below.

When i ran the program initially, you might also encounter an exception like shown above.
Exception: Application Failed to Start : Web server failed to start: Port 8080 is already in use.
This is because, spring boot tries to start in the default 8080 port and your machine might already have other services running on the 8080 port.
There are two things that we do usually to fix this exception:
a. We can configure a new port in application.properties ( i will keep this for another post )
b. we can kill the service that is running on port 8080 and re-run our spring boot application.
For this tutorial, we will kill the service running on port 8080 following the instructions in the bellow section.
Once you kill the service, rerun the spring boot application in eclipse and the service should start.

If you go to your browser and load http://localhost:8080/ it will give you a white-label error. But no need to panic. your project is running properly. Its just that it doesn’t have anything to load.

How to Force Kill a windows process running on port 8080
Following steps will show you how to search for a the pid of the process running on port 8080 and force kill the process
- Goto Start and open the command prompt in admin mode. As shown below

2. Run this netstat command to find what service or process is running on port 8080
>netstat -ano | findstr 8080

3. To force kill the process , run the following command with the pid that you got from the netstat command above. In my case pid 6684 is running TCP.
>taskkill /F /pid 6684

Now the port 8080 is free for your application to run.