🧾 1. Introduction to Spring Framework
Before diving into Spring Boot, it’s important to understand the Spring Framework. Spring is a comprehensive programming and configuration model for modern Java-based enterprise applications. It supports:
-
Dependency Injection (DI)
-
Aspect-Oriented Programming (AOP)
-
Transaction Management
-
MVC (Model-View-Controller)
-
Data Access and Security
However, configuring a Spring application manually involves writing a lot of boilerplate code, XML configurations, and dealing with complex setups. That's where Spring Boot comes in.
🚀 2. What is Spring Boot?
Spring Boot is an opinionated framework built on top of the Spring Framework. Its goal is to simplify the setup, development, and deployment of new Spring applications by eliminating boilerplate configuration.
Key Characteristics:
-
No need for XML configurations
-
Embedded servers (Tomcat, Jetty, Undertow)
-
Auto-configuration based on project dependencies
-
Spring Boot starters for quick setup
-
Production-ready features (metrics, health checks, etc.)
Motto:
"Just run your Java application without worrying about configuring the environment."
🌟 3. Key Features of Spring Boot
Feature | Description |
---|---|
Auto-Configuration | Automatically configures Spring app based on included JARs |
Spring Boot Starters | Set of convenient dependency descriptors |
Embedded Server | Comes with embedded Tomcat/Jetty/Undertow |
Production-Ready | Health checks, metrics, environment info via Actuator |
Spring Boot CLI | Command-line interface to run Groovy scripts |
No Code Generation | Uses existing Spring libraries |
Developer Productivity | Simplified project creation and testing |
🧱 4. Spring Boot Architecture
Spring Boot’s architecture is designed for modular and layered application development:
-
Spring Core Container
-
Auto Configuration Module
-
Spring Boot Starters
-
Spring Boot Actuator
-
Embedded Servlet Containers
-
Externalized Configuration (via
application.properties
orapplication.yml
) -
Logging (SLF4J + Logback)
Spring Boot uses Spring’s Inversion of Control (IoC) and Dependency Injection (DI) principles under the hood, and adds powerful defaults on top of them.
📦 5. Spring Boot Starters
Starters are pre-defined dependency descriptors. Instead of including multiple dependencies manually, you can just use one starter.
Common Starters:
-
spring-boot-starter-web
– Web development -
spring-boot-starter-data-jpa
– JPA & Hibernate -
spring-boot-starter-security
– Security -
spring-boot-starter-test
– Testing tools -
spring-boot-starter-thymeleaf
– Templating engine
These starters make dependency management clean and easy.
⚙️ 6. Spring Boot Auto-Configuration
Spring Boot inspects the libraries on the classpath and automatically configures the necessary beans. For example:
-
If
spring-boot-starter-web
is present, it configures a web app with embedded Tomcat. -
If
spring-boot-starter-data-jpa
is found, it configures a data source and JPA repositories.
You can override these default configurations by creating your own @Bean
or disabling auto-config using @EnableAutoConfiguration(exclude=...)
.
🔖 7. Spring Boot Annotations Explained
Here are some commonly used annotations:
Annotation | Purpose |
---|---|
@SpringBootApplication |
Combines @Configuration , @EnableAutoConfiguration , and @ComponentScan |
@RestController |
Combines @Controller and @ResponseBody |
@RequestMapping |
Maps HTTP requests |
@GetMapping , @PostMapping , etc. |
Shorthand for @RequestMapping |
@Autowired |
Injects dependencies |
@Component , @Service , @Repository |
Marks a class as a Spring bean |
@Value |
Injects values from properties |
@EnableAutoConfiguration |
Enables Spring Boot’s auto-configuration |
🆚 8. Spring Boot vs Spring Framework
Feature | Spring Framework | Spring Boot |
---|---|---|
Setup | Manual | Auto-configured |
XML Config | Required (older) | Not required |
Embedded Server | No | Yes |
Dependency Management | Manual | Starters |
Suitable For | Large-scale custom enterprise apps | Microservices, REST APIs, quick dev |