Project Structure and the Magic of Starters

Site Admin · 11 Sep 2026 · 5 views

Project Structure and the Magic of Starters

A generated Spring Boot project has a small, predictable layout. Understanding where things live makes new code land in the right place and keeps the build simple. The convention is that your main class sits in the root package of your application so component scanning finds everything beneath it.

Layout essentials

Under src/main/java you write Java code, typically split into controller, service, repository, and model packages. src/main/resources holds application.properties, static content, and templates. Tests live under src/test/java, and the build file - pom.xml or build.gradle - sits at the root.

How a starter works

A starter is simply a module that groups dependencies. When the classpath contains, say, Tomcat and Spring MVC, auto-configuration activates the web layer. When you add JPA and an H2 database, the persistence auto-configuration kicks in. Add a starter and Boot reacts; remove it and the feature quietly disappears.

Why the root package rule matters

Keep your main class in com.yourcompany.app and all other packages underneath it. If scanning starts from the wrong place, Spring silently registers nothing, and the confusing symptom is a 404 or a missing bean. The project structure is your first debugging tool.

Resource organization

Static files like CSS and images go in src/main/resources/static. Thymeleaf templates live in src/main/resources/templates. Custom configuration snippets are usually split into application-<profile>.properties files that activate per environment.

Key Points

  • Keep the main class in the root package so component scanning finds everything.
  • Separate controllers, services, repositories, and models into clear packages.
  • Starters group compatible dependencies and trigger auto-configuration by presence.
  • Templates, static files, and configuration live under src/main/resources.
  • Predictable structure makes projects approachable and easy to extend.
Share this post:

Comments (0)

Please login or register to comment.