Course Content
Spring Boot Backend
Spring Boot Backend
Project structure
Now we move on to the most exciting part, where we will run our first Spring Boot application using a practical example and break down the project structure.
I will be using IntelliJ IDEA, but make sure to use the Ultimate version to work with Spring Boot. Well, let's get started!
Project Creation
First, create a new project, and in the left panel, you will see Spring Boot — you need to select that.
Next, you should configure the project settings the same way I do. You can use any Java version, it's not crucial. Make sure to select Maven as the build type!
After clicking the Next
button, you will see a window showing the dependencies that will be included in our application.
You need to select Web
-> Spring MVC
. We need Spring MVC
to develop web applications that separate business logic, presentation, and request handling.
Just create your project, and you're all set! Let's quickly go over the project structure.
Project Structure
Initially, you will have a structure like this, and the file that stands out the most is pom.xml
, which represents Maven. Let's take a look at it.
You might notice a lot of code that may seem unclear, but for now, the block we are interested in is inside the <dependencies>
</dependencies>
tags.
Here, we can add the dependencies we selected when creating the project (like Spring MVC
). If you didn't do this earlier, you can simply add the required code inside the <dependencies>
</dependencies>
tags.
After that, update the configuration by clicking this button. This will pull all the dependencies into the project.
There's also the src
directory, which, when expanded, reveals two more directories called main
and test
. The test
directory is used for writing tests, but we will cover that in other sections.
When we expand the main
directory, we see two more directories: java
and resources
.
The resources
directory is used to store all the resources for our website. HTML
files are kept in the templates
directory, while everything else (like CSS
, JS
files, and images) is stored in the static
folder. Additionally, there's the application.properties
file, where we specify extra project settings.
This file specifies the port on which the server will run, but you can change it, and the server will start on a different port. This file will be essential when we connect to a database, so we will study it in detail a bit later.
Finally, in the java
directory, you'll find the path to our main class.
Where does the Application Itself Launch?
In the screenshot, you can clearly see where the main class for running the application is located. Within the directory where the main class is found, you can write your own classes and run your applications.
Now, let's run our first application and check if everything works as expected.
If you have started the server and you see logs like these in the console, then congratulations, everything is working!
Summary
In a Spring Boot project, the structure includes the main application class and configuration files, which are located in src/main/resources
. The focus is on simplifying configuration and enabling rapid deployment of the application.
Everything was clear?