In this article, I describe:
- The initialization of a Maven project;
- The initialization of a Spring Boot project;
- The necessary dependencies to create a web project;
- The entry point of a Spring Boot project.
For more details check this explanatory video.
Link to the GIT repository.
The initialization of a Maven project
Let’s use the IDE to create the project. In my case we use IntelliJ, but it’s the same with the other IDEs. To create a new Maven project:
- File -> New… -> Project
- Choose a Maven projet and Next
- Specify the name and the location, the groupId and the artifact.

Now we have the project. An empty Maven project. In the project structure I can see the created folders. Which are:
- the idea folder, it’s an internal file on my IntelliJ.
- the src folder, where all the code will be.
- backend-social-network.iml, which is another internal file.
- and the most important file of a Maven project, the pom.xml.

As I said, it’s an empty project. But it already has the structure of a Maven project. As we see, the source folder with the main and the test folders and inside the folders the Java and the resources folder. But all empty.
The initialization of a Spring Boot project
Let’s go now with the pom.xml. At the top, I have a project tag with some stuff here this is only to validate you don’t create types that are not supported by Maven. The version of the pom.xml and the definition of our our project which is splitted into group ID artifact ID.
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sergio.socialnetwork</groupId>
<artifactId>backend-social-network</artifactId>
<version>1.0-SNAPSHOT</version>
- By convention, the group ID is the name of the organization
- The artifact ID is the name of the project
- And the version is the current version of the project
Let’s go now with Spring Boot. Spring Boot will allows me to start the project very quickly. There are already has a lot of stuff configurated. As the database, the dependency injection and more. So, how do I set this project as a Spring Boot one?
I must specify a parent saying that this project will inherit all the Spring Boot architecture. And inside, add the Spring Boot dependency.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
</parent>
This information was taken from the Maven Central Repository (https://mvnrepository.com/). Searching from the Spring Boot Starter Parent dependency (https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent/2.2.6.RELEASE).
The necessary dependencies to create a web project
Now my project inherits everything from a Spring Boot project. but a regular Spring project. I have to specify that I want a web project. Go back to the Maven Central Repository and search now for Spring Boots starter web: https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web/2.2.6.RELEASE
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
Take any version, copy and past into the dependency. Now I can remove the version information. Because it’s already inherited from the parent. And that’s all. Two dependencies and my web project is ready.
additionally I will only add the Java version property. This way, I will let Maven use the correct compiler.
<properties>
<java.version>11</java.version>
</properties>
With this, Maven configures the version of the compiler and the runtime.
The entry point of a Spring Boot project
And now, let’s try to run it.
I create a maven package and an Application class with the main method. And to start our application, I also need to specify that’s a Spring Boot application with the following annotation:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Now I can run it.

You can see that the Tomcat server was started, which will allow the web communication at port 8080. And that’s all.
Starting Application on MyLaptop with PID 19433 ()
No active profile set, falling back to default profiles: default
Tomcat initialized with port(s): 8080 (http)
Starting service [Tomcat]
Starting Servlet engine: [Apache Tomcat/9.0.33]
Initializing Spring embedded WebApplication
ContextRoot WebApplicationContext: initialization completed in 1331 ms
HHH000204: Processing PersistenceUnit
Info [name: default]
HHH000412: Hibernate ORM core version 5.4.12.Final
HikariPool-1 - Starting...
HikariPool-1 - Start completed.
Tomcat started on port(s): 8080 (http) with context path ''
Started Application in 4.14 seconds (JVM running for 6.503)
Only those two dependencies and the main class and I have a web application ready. In the following articles, I will add the logic inside but the configuration is already done. One last step for today, the Git repository.
Go to the project folder. Initiate a git repository.
» git init
Create a gitignore file to avoid storing too many files into the repository.
» cat .gitignore
.idea/
backend-social-network.iml
target/
»
Now, add the rest of the files to the index and create the first commit.
» git add .
» git commit -m "Initial commit"
Here’s the first commit of the Spring Boot application, of our backend application.



Leave a reply to Controllers and Services with Spring Boot – The Dev World – by Sergio Lema Cancel reply