Spring Boot Setup
BeginnerSpring Boot eliminates boilerplate setup through auto-configuration and starter dependencies. A production-ready app can be running in under 5 minutes with the right project structure.
Overview
Spring Initializr (start.spring.io) generates a Maven or Gradle project with a parent POM that manages all dependency versions via the spring-boot-dependencies BOM. Starters (spring-boot-starter-web, spring-boot-starter-data-jpa, etc.) bundle related libraries with pre-tested compatible versions. Auto-configuration then inspects the classpath and registered beans to configure the application without any XML — if spring-boot-starter-web is on the classpath, Tomcat, DispatcherServlet, and Jackson are configured automatically.
pom.xml & Starter Dependencies
The spring-boot-starter-parent POM provides sensible defaults: Java version, encoding, plugin configuration, and dependency management via spring-boot-dependencies BOM. You only specify version once (the Spring Boot version) and all starters use compatible library versions.
<!-- pom.xml — minimal Spring Boot web app -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.0</version>
</parent>
<dependencies>
<!-- Web: Tomcat + Spring MVC + Jackson -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- JPA: Hibernate + Spring Data -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- PostgreSQL driver -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<!-- Test: JUnit 5, Mockito, MockMvc -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Builds executable fat JAR with java -jar -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>Project Structure
Spring Boot has a conventional package structure. The main class with @SpringBootApplication should be in the root package — @ComponentScan will then automatically pick up all classes in sub-packages. Placing it in a sub-package means you need explicit basePackages.
src/
└── main/
├── java/
│ └── com/aicancode/toolhub/ ← root package
│ ├── ToolhubApplication.java ← @SpringBootApplication here
│ ├── controller/ ← @RestController classes
│ ├── service/ ← @Service classes
│ ├── repository/ ← @Repository / JPA interfaces
│ ├── model/ ← @Entity classes
│ ├── dto/ ← request/response POJOs
│ ├── config/ ← @Configuration classes
│ └── exception/ ← custom exceptions + @ControllerAdvice
└── resources/
├── application.yml ← main config
├── application-dev.yml ← dev overrides
├── application-prod.yml ← prod overrides
└── db/migration/ ← Flyway SQL scripts
// Main class — @SpringBootApplication in root package
@SpringBootApplication
public class ToolhubApplication {
public static void main(String[] args) {
SpringApplication.run(ToolhubApplication.class, args);
}
}Key Points to Remember
- 1spring-boot-starter-parent manages all dependency versions — never specify library versions manually.
- 2Starters bundle related libraries with compatible versions; you pick the feature, Spring picks the versions.
- 3@SpringBootApplication must be in the root package for @ComponentScan to find all sub-packages.
- 4Auto-configuration is conditional — it backs off when you declare your own beans.
- 5spring-boot-maven-plugin produces a fat executable JAR runnable with java -jar.
- 6Use application-{profile}.yml for environment-specific overrides (dev, prod, test).
Interview Questions
Sign in to ask AriaWhat does spring-boot-starter-parent provide?
What is a Spring Boot Starter and how does it differ from a regular dependency?
Why should @SpringBootApplication be in the root package?
How would you exclude a specific auto-configuration class?
What is the spring-boot-dependencies BOM and why is it useful?
Ask Aria about Spring Boot Setup
Your personal AI tutor — ask anything about this concept
Revision Status
Personal Notes
Sign in to save personal notes for this topic.
Discussion
Sign in to join the discussion.