Setting Up a Spring Boot Project
Use Spring Initializr to scaffold a project in seconds, understand the standard layout , the @SpringBootApplication main class, and how Maven or Gradle wires it all together into a runnable app.
Learn Setting Up a Spring Boot Project in our free Java course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a quick…
Part of the free Java course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
Read the Introduction to Spring & Spring Boot first, and make sure you understand annotations , since the whole setup is annotation-driven.
💡 Analogy: Spring Initializr is like moving into a pre-furnished apartment : the rooms (folders) are already laid out, the utilities (build file, plugins) are connected, and a working light switch (the main class) is installed. You just walk in and start living — adding your own furniture (controllers, services) where it belongs.
The standard layout is a convention every Spring developer recognises, so anyone can find their way around your project instantly.
At start.spring.io you pick the build tool (Maven/Gradle), language, Boot version, project metadata and the starters you need. It downloads a zip with the build file, layout and a ready-to-run main class.
The generated main class carries @SpringBootApplication and a main that calls SpringApplication.run(...) . Keep it at the root of your package tree so component scanning discovers everything below it.
The parent (Maven) or Boot plugin (Gradle) manages compatible versions, you declare starters as dependencies, and the Boot plugin repackages a runnable jar.
Every Spring Boot project follows the same Maven-standard directory structure, so any developer can navigate it instantly. Code in src/main/java , config in src/main/resources , tests in src/test/java .
Answer: component scanning starts from its package, so beans in sub-packages are only found if they live below it.
Answer: in src/main/resources/application.properties with server.port=8081 — no recompile needed.
Answer: the spring-boot-maven-plugin repackages it into an executable 'fat' jar with the embedded server inside.
You can now scaffold a project with Spring Initializr, recognise the standard layout, understand the @SpringBootApplication main class and SpringApplication.run() , and know where dependencies and configuration live in Maven or Gradle.
Next up: IoC Container & Dependency Injection — how the ApplicationContext creates and wires your beans.
Practice quiz
What is Spring Initializr (start.spring.io)?
- A web tool that generates a starter Spring Boot project skeleton
- A database admin console
- A Java compiler
- A package manager for npm
Answer: A web tool that generates a starter Spring Boot project skeleton. Spring Initializr lets you pick build tool, language, Boot version and dependencies, then downloads a ready-to-run project.
On which class do you place @SpringBootApplication?
- Every service class
- The main application class that contains main()
- The pom.xml
- Every controller
Answer: The main application class that contains main(). @SpringBootApplication goes on the single main class whose main() method calls SpringApplication.run(...).
Why should the main class live at the root of your package tree?
- For shorter file names
- Component scanning starts from its package, so it finds sub-package beans
- Java requires it
- To avoid imports
Answer: Component scanning starts from its package, so it finds sub-package beans. @ComponentScan (inside @SpringBootApplication) scans the main class's package and below, so beans must live under it.
Which line actually launches the application inside main()?
- new Application();
- System.out.println(...)
- SpringApplication.run(App.class, args);
- Application.start();
Answer: SpringApplication.run(App.class, args);. SpringApplication.run(App.class, args) creates the context, runs auto-configuration and starts the server.
What is a Spring Boot 'starter' dependency?
- A single jar with no transitive dependencies
- A curated bundle of compatible dependencies for a use case
- A test framework only
- An IDE plugin
Answer: A curated bundle of compatible dependencies for a use case. A starter such as spring-boot-starter-web pulls in a coherent set of libraries so you don't hand-pick versions.
In a Maven Spring Boot project, where are dependencies declared?
- build.gradle
- package.json
- pom.xml
- settings.xml
Answer: pom.xml. Maven projects declare dependencies in pom.xml; Gradle projects use build.gradle instead.
Which build tools does Spring Initializr support out of the box?
- Only Maven
- Maven and Gradle
- Only Gradle
- Only Ant
Answer: Maven and Gradle. Initializr lets you choose either Maven or Gradle as the build tool for the generated project.
Where do non-code settings like server.port usually go?
- pom.xml
- src/main/resources/application.properties (or .yml)
- The main method
- README.md
Answer: src/main/resources/application.properties (or .yml). Externalised configuration lives in application.properties or application.yml under src/main/resources.
What does the spring-boot-maven-plugin enable?
- Building a runnable 'fat' jar and running the app with the plugin
- Compiling TypeScript
- Generating UML
- Encrypting passwords
Answer: Building a runnable 'fat' jar and running the app with the plugin. The Boot Maven plugin repackages the app into an executable jar and provides the spring-boot:run goal.
In the standard layout, where does application code live?
- src/test/java
- src/main/java
- target/
- src/main/resources
Answer: src/main/java. Production Java source lives under src/main/java; tests go in src/test/java and resources in src/main/resources.