Bird
Raised Fist0
Spring Bootframework~10 mins

Project structure walkthrough in Spring Boot - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Project structure walkthrough
Start: Spring Boot Project Creation
↓
Create src/main/java folder
↓
Add Application class with @SpringBootApplication
↓
Create packages: controller, service, repository
↓
Add classes in each package
↓
Create src/main/resources folder
↓
Add application.properties or application.yml
↓
Create src/test/java for tests
↓
Build & Run Project
This flow shows the main steps to build a Spring Boot project structure from creation to running.
Execution Sample
Spring Boot
src/
  main/
    java/
      com/example/demo/
        DemoApplication.java
        controller/
          HelloController.java
        service/
          HelloService.java
    resources/
      application.properties
This shows the typical folder and file layout of a Spring Boot project.
Execution Table
StepActionFolder/File CreatedPurpose
1Create project root folderdemo/Base folder for project
2Create source foldersrc/main/javaJava source code location
3Create main packagecom/example/demoNamespace for code
4Add main classDemoApplication.javaEntry point with @SpringBootApplication
5Create controller packagecontroller/Handles web requests
6Add controller classHelloController.javaDefines REST endpoints
7Create service packageservice/Business logic layer
8Add service classHelloService.javaImplements logic
9Create resources foldersrc/main/resourcesStatic resources and config
10Add config fileapplication.propertiesApp configuration
11Create test foldersrc/test/javaUnit and integration tests
12Build and run projectN/ACompile and start Spring Boot app
💡 All main folders and files created, project ready to build and run
Variable Tracker
Folder/FileBeforeAfter Step 1After Step 2After Step 3After Step 4After Step 5After Step 6After Step 7After Step 8After Step 9After Step 10After Step 11Final
demo/Not existExistsExistsExistsExistsExistsExistsExistsExistsExistsExistsExistsExists
src/main/javaNot existNot existExistsExistsExistsExistsExistsExistsExistsExistsExistsExistsExists
com/example/demoNot existNot existNot existExistsExistsExistsExistsExistsExistsExistsExistsExistsExists
DemoApplication.javaNot existNot existNot existNot existExistsExistsExistsExistsExistsExistsExistsExistsExists
controller/Not existNot existNot existNot existNot existExistsExistsExistsExistsExistsExistsExistsExists
HelloController.javaNot existNot existNot existNot existNot existNot existExistsExistsExistsExistsExistsExistsExists
service/Not existNot existNot existNot existNot existNot existNot existExistsExistsExistsExistsExistsExists
HelloService.javaNot existNot existNot existNot existNot existNot existNot existNot existExistsExistsExistsExistsExists
src/main/resourcesNot existNot existNot existNot existNot existNot existNot existNot existNot existExistsExistsExistsExists
application.propertiesNot existNot existNot existNot existNot existNot existNot existNot existNot existNot existExistsExistsExists
src/test/javaNot existNot existNot existNot existNot existNot existNot existNot existNot existNot existNot existExistsExists
Key Moments - 3 Insights
Why do we create separate packages like controller, service, and repository?
Separating code into packages helps organize by role: controller handles web requests, service contains business logic, and repository manages data access. This is shown in steps 5-8 in the execution_table.
What is the purpose of the DemoApplication.java class?
DemoApplication.java is the main entry point annotated with @SpringBootApplication. It starts the Spring Boot app. This is created at step 4 in the execution_table.
Why do we have src/main/resources folder?
src/main/resources holds configuration files and static resources like application.properties. This folder is created at step 9 and config file added at step 10.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step is the main application class created?
AStep 6
BStep 4
CStep 9
DStep 11
💡 Hint
Check the 'Folder/File Created' column for DemoApplication.java in execution_table
According to variable_tracker, when does the 'controller/' package first exist?
AAfter Step 5
BAfter Step 7
CAfter Step 3
DAfter Step 9
💡 Hint
Look at the 'controller/' row in variable_tracker and find when it changes from 'Not exist' to 'Exists'
If we skip creating src/test/java, which step in execution_table would be missing?
AStep 10
BStep 7
CStep 11
DStep 12
💡 Hint
Step 11 in execution_table is about creating the test folder src/test/java
Concept Snapshot
Spring Boot project structure:
- src/main/java: Java code
- Main class with @SpringBootApplication
- Packages: controller (web), service (logic), repository (data)
- src/main/resources: config files
- src/test/java: tests
Organizing code this way keeps project clean and manageable.
Full Transcript
This visual execution shows how a Spring Boot project is structured step-by-step. We start by creating the main source folder and package. Then we add the main application class with the @SpringBootApplication annotation. Next, we create separate packages for controller, service, and repository to organize code by responsibility. We add classes in each package accordingly. The resources folder holds configuration files like application.properties. Finally, we create a test folder for unit and integration tests. This structure helps keep the project clean and easy to maintain. The execution table and variable tracker show when each folder and file is created. Key moments clarify why we separate packages and the role of the main class. The quiz tests understanding of these steps.

Practice

(1/5)
1. In a typical Spring Boot project, where should you place your main application Java files?
easy
A. src/resources/java
B. src/main/resources
C. src/test/java
D. src/main/java

Solution

  1. Step 1: Understand Spring Boot folder roles

    The src/main/java folder is for main Java source code including the application entry point.
  2. Step 2: Identify correct folder for main Java files

    Main application files should not be in resources or test folders, so src/main/java is correct.
  3. Final Answer:

    src/main/java -> Option D
  4. Quick Check:

    Main Java code = src/main/java [OK]
Hint: Main Java code always goes under src/main/java [OK]
Common Mistakes:
  • Confusing resources folder with Java source folder
  • Placing main code in test folder
  • Using incorrect folder names like src/resources/java
2. Which file is commonly used to manage dependencies and build steps in a Spring Boot Maven project?
easy
A. pom.xml
B. application.properties
C. build.gradle
D. settings.xml

Solution

  1. Step 1: Identify build tool for Maven projects

    Maven uses pom.xml to manage dependencies and build configuration.
  2. Step 2: Differentiate from Gradle and config files

    build.gradle is for Gradle, application.properties is for app config, and settings.xml is not for dependencies.
  3. Final Answer:

    pom.xml -> Option A
  4. Quick Check:

    Maven build file = pom.xml [OK]
Hint: Maven uses pom.xml; Gradle uses build.gradle [OK]
Common Mistakes:
  • Confusing application.properties with build files
  • Mixing Gradle and Maven build files
  • Thinking settings.xml manages dependencies
3. Given this Spring Boot project structure snippet, where will the test Java files be located?
src/
  main/
    java/
    resources/
  test/
    java/
    resources/
medium
A. src/main/resources
B. src/test/java
C. src/main/java
D. src/test/resources

Solution

  1. Step 1: Understand test folder purpose

    The src/test/java folder is for Java test source files.
  2. Step 2: Identify test Java files location

    Test Java files go under src/test/java, not in main or resources folders.
  3. Final Answer:

    src/test/java -> Option B
  4. Quick Check:

    Test Java code = src/test/java [OK]
Hint: Test Java files go in src/test/java folder [OK]
Common Mistakes:
  • Putting test Java files in src/main/java
  • Confusing test resources with test Java code
  • Using src/main/resources for tests
4. You accidentally placed your application.properties file inside src/main/java. What problem will this cause?
medium
A. The application will fail to start due to missing config
B. The build will fail with a syntax error
C. The properties file will be ignored and default config used
D. The application.properties will be loaded correctly anyway

Solution

  1. Step 1: Know where Spring Boot loads config files

    Spring Boot loads application.properties from src/main/resources or classpath root.
  2. Step 2: Effect of wrong file location

    If placed in src/main/java, it won't be found and ignored, so defaults apply.
  3. Final Answer:

    The properties file will be ignored and default config used -> Option C
  4. Quick Check:

    Config files must be in resources, else ignored [OK]
Hint: Config files must be in resources folder to load [OK]
Common Mistakes:
  • Assuming app fails to start immediately
  • Thinking build fails due to config file location
  • Believing misplaced properties still load
5. You want to add a new configuration file for your Spring Boot app that should be packaged inside the jar and accessible at runtime. Where should you place this file?
hard
A. src/main/resources/config
B. src/main/java/config
C. src/test/resources/config
D. src/main/resources/static

Solution

  1. Step 1: Understand resource packaging in Spring Boot

    Files in src/main/resources are packaged inside the jar and available at runtime.
  2. Step 2: Choose correct folder for config files

    Config files should be under src/main/resources/config to be included and organized.
  3. Final Answer:

    src/main/resources/config -> Option A
  4. Quick Check:

    Runtime config files go in src/main/resources [OK]
Hint: Put runtime config files in src/main/resources folder [OK]
Common Mistakes:
  • 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
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard