A clear project structure helps you find and organize your code easily. It makes your Spring Boot app neat and simple to work on.
Project structure walkthrough in Spring Boot
src
├── main
│ ├── java
│ │ └── com.example.project
│ │ ├── controller
│ │ ├── service
│ │ ├── repository
│ │ └── Application.java
│ └── resources
│ ├── application.properties
│ └── static
└── test
└── java
└── com.example.project
└── ApplicationTests.javasrc/main/java holds your Java code organized by packages.
src/main/resources contains config files and static assets like images or CSS.
src/main/java/com/example/project/controller/UserController.java
src/main/java/com/example/project/service/UserService.java
src/main/java/com/example/project/repository/UserRepository.java
src/main/resources/application.properties
This is the main class that starts your Spring Boot app. It lives in the base package.
package com.example.project; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
Keep your package names clear and consistent to avoid confusion.
Place test classes in src/test/java mirroring your main code packages.
Use resources/static for files like images, CSS, and JavaScript that your app serves.
Spring Boot projects have a standard folder layout to organize code and resources.
Main Java code goes under src/main/java with packages like controller, service, and repository.
Configuration and static files go under src/main/resources.
Practice
Solution
Step 1: Understand Spring Boot folder roles
Thesrc/main/javafolder is for main Java source code including the application entry point.Step 2: Identify correct folder for main Java files
Main application files should not be in resources or test folders, sosrc/main/javais correct.Final Answer:
src/main/java -> Option DQuick Check:
Main Java code = src/main/java [OK]
- Confusing resources folder with Java source folder
- Placing main code in test folder
- Using incorrect folder names like src/resources/java
Solution
Step 1: Identify build tool for Maven projects
Maven usespom.xmlto manage dependencies and build configuration.Step 2: Differentiate from Gradle and config files
build.gradleis for Gradle,application.propertiesis for app config, andsettings.xmlis not for dependencies.Final Answer:
pom.xml -> Option AQuick Check:
Maven build file = pom.xml [OK]
- Confusing application.properties with build files
- Mixing Gradle and Maven build files
- Thinking settings.xml manages dependencies
src/
main/
java/
resources/
test/
java/
resources/Solution
Step 1: Understand test folder purpose
Thesrc/test/javafolder is for Java test source files.Step 2: Identify test Java files location
Test Java files go undersrc/test/java, not in main or resources folders.Final Answer:
src/test/java -> Option BQuick Check:
Test Java code = src/test/java [OK]
- Putting test Java files in src/main/java
- Confusing test resources with test Java code
- Using src/main/resources for tests
src/main/java. What problem will this cause?Solution
Step 1: Know where Spring Boot loads config files
Spring Boot loadsapplication.propertiesfromsrc/main/resourcesor classpath root.Step 2: Effect of wrong file location
If placed insrc/main/java, it won't be found and ignored, so defaults apply.Final Answer:
The properties file will be ignored and default config used -> Option CQuick Check:
Config files must be in resources, else ignored [OK]
- Assuming app fails to start immediately
- Thinking build fails due to config file location
- Believing misplaced properties still load
Solution
Step 1: Understand resource packaging in Spring Boot
Files insrc/main/resourcesare packaged inside the jar and available at runtime.Step 2: Choose correct folder for config files
Config files should be undersrc/main/resources/configto be included and organized.Final Answer:
src/main/resources/config -> Option AQuick Check:
Runtime config files go in src/main/resources [OK]
- Placing config files in src/main/java which is for code
- Using test resources folder which is not packaged
- Putting config in static folder meant for web assets
Ready to prove it?
Pass the test and this pattern moves unknown
