Spring BasicsCore· 30 min read

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:

PathWhat it is
src/main/java/...Your Java code (controllers, models, etc.)
...Application.javaThe main class that starts the app
src/main/resources/application.propertiesSettings (port, database, etc.)
pom.xmlThe 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.

The main class — the single entry point of the app
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:

pom.xml: the Spring Web starter dependency
<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?

Answer: The @SpringBootApplication class holds the main method that starts everything and tells Spring which package to scan for your components.

✍️ Practice

  1. Open your project and find the main class and application.properties.
  2. Open pom.xml and find the spring-boot-starter-web dependency.

🏠 Homework

  1. Write a short note listing the five key files/folders and one sentence on what each does.
Want to learn this with a mentor?

CodingClave runs guided, project-based training (28-day, 45-day & 6-month batches).

Explore Training →