Project Structure
A Spring Boot Maven project follows the standard layout: application code under src/main/java, resources under src/main/resources, tests mirroring main under src/test.
Introduction
A Spring Boot Maven project follows the standard layout: application code under src/main/java, resources under src/main/resources, tests mirroring main under src/test. Tooling, IDEs, and Spring Boot's default component scan assume this shape.
Place OrdersApplication in com.techlearningpro.orders. Component scan starts at that package and walks downward. Controllers, services, and config that live in a sibling package outside that root will not become beans unless you widen scanBasePackages on purpose.
Early Orders can use layer packages (controller, service, repository). As the service grows, feature packages (pricing, fulfillment) often reduce merge pain — the dependency rule from the architecture lesson does not change.
Configuration belongs in application.yml (this course's default). Flyway/Liquibase scripts later land under db/migration. Never commit target/.
Purpose of this lesson
Navigate the Orders Maven tree, place the application class correctly for component scan, and choose a package layout that will not fight Boot defaults.
Understanding the topic
Structure is a contract with the build and with Spring.
- Entry class:
@SpringBootApplicationat the root package of the service. - resources: YAML, static assets, migration scripts — not Java.
- tests: same package names as main so package-private test tricks stay available.
- build output:
target/is disposable; CI recreates it. - wrappers:
mvnwlives at the repo root beside the POM.
Step-by-step explanation
- Open the unzipped Orders project and locate
OrdersApplication.java. - Confirm its package is the ancestor of your controller package.
- Add empty
controller,service, anddtopackages under that root. - Run
./mvnw -q testafter any package move to catch scan mistakes early.
Syntax reference
Reference tree for Fundamentals:
orders/├── pom.xml├── mvnw / mvnw.cmd├── src/main/java/com/techlearningpro/orders/│ ├── OrdersApplication.java│ ├── controller/│ ├── service/│ ├── dto/│ └── config/├── src/main/resources/│ └── application.yml└── src/test/java/com/techlearningpro/orders/
Real-world use
When a new engineer joins TechLearningPRO checkout, they expect the application class at the scan root and YAML under resources. Surprises — business logic in config, or controllers in com.techlearningpro.api outside the scan — cost hours of 'why is everything 404'.
Best practices
- Keep the application class at the service root package.
- Mirror main packages in test.
- Switch to feature packages when layer folders become dump grounds.
Common mistakes
- Moving
OrdersApplicationto a deeper package and leaving controllers above it. - Committing IDE files and
target/. - Putting secrets in
src/main/resourcesbecause 'it is not code'.
Advanced interview questions
Interview Prep
Practice concise answers, then expand each card for the explanation.
1BeginnerQuestionWhere should @SpringBootApplication live?+
Answer
2IntermediateQuestionWhat happens if a @RestController sits outside the scan base package?+
Answer
3AdvancedQuestionPackage-by-layer vs package-by-feature — how do you choose?+
Answer
Hands-on exercise
Lab. Draw your Orders tree. Mark the scan root with a star. Intentionally move a future controller package outside it on paper and write what symptom you would see at runtime (empty mappings / 404 while the process is healthy).
Summary
Orders is a standard Maven tree with a deliberate scan root. Next you write the first controller and prove the process serves JSON.