The Project Structure
A Spring Boot project has a few key files and folders — know these and you will never feel lost.
What you will learn
- Find the main application class
- Know where your code and config live
- Understand pom.xml at a glance
The files that matter
A fresh project looks busy, but only a handful of things matter at the start. Here are the key ones:
| Path | What it is |
|---|---|
src/main/java/... | Your Java code (controllers, models, etc.) |
...Application.java | The main class that starts the app |
src/main/resources/application.properties | Settings (port, database, etc.) |
pom.xml | The list of dependencies (libraries) you use |
src/test/java/... | Your tests |
The main class
Every Spring Boot app has one main class with a main method — the entry point, just like any Java program. It carries one special annotation.
package com.codingclave.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}Note: Output:
(No printed output — running this starts the whole app and the web server.)
The one line SpringApplication.run(...) boots everything: it scans your code, wires it together, and starts Tomcat.
The @SpringBootApplication annotation turns this ordinary class into the heart of a Spring app. Among other things, it tells Spring to scan this package and its sub-packages for your other classes (controllers, services). That is why your code lives next to this class.
A peek at pom.xml
The pom.xml file lists your dependencies. When you added Spring Web on Initializr, an entry like this appeared:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>Note: Output:
(No output — this is configuration.)
Maven reads pom.xml, downloads this library and everything it needs, and adds it to your project. To add a feature later, you add a dependency here.
Tip: Rule of thumb: keep your new classes in the same package or a sub-package of the main ...Application.java class. Then Spring finds them automatically with no extra config.
Q. What is the job of the class marked with @SpringBootApplication?
✍️ Practice
- Open your project and find the main class and application.properties.
- Open pom.xml and find the spring-boot-starter-web dependency.
🏠 Homework
- Write a short note listing the five key files/folders and one sentence on what each does.