First, the Basics
-
Spring Framework (a.k.a Spring):
A comprehensive framework for building Java applications.
It provides dependency injection, aspect-oriented programming, data access, web MVC, security, etc.
But it requires a lot of manual configuration. -
Spring Boot:
A framework built on top of Spring that makes development faster, easier, and less error-prone by removing configuration overhead.
It comes with auto-configuration, starter dependencies, embedded servers, and production-ready features.
Spring = Buying raw ingredients and cooking everything yourself.
Spring Boot = Ordering a ready-made meal kit that comes pre-measured, half-cooked, and ready in 10 minutes.
Key Differences
Feature / Aspect | Spring Framework | Spring Boot |
---|---|---|
Configuration | Manual XML/Java config needed | Auto-configuration (smart defaults) |
Setup Time | Long (set up Tomcat, DataSource, beans manually) | Short (starters + embedded server) |
Server | Requires external server (Tomcat, Jetty, etc.) | Comes with embedded Tomcat/Jetty/Undertow |
Dependencies | Must specify each library | Uses starter dependencies (bundled) |
Deployment | Typically WAR file deployment | Run as a standalone JAR (java -jar app.jar ) |
Production Features | Must integrate manually (monitoring, metrics) | Built-in via Spring Boot Actuator |
Learning Curve | Steeper (more boilerplate) | Easier (opinionated defaults) |
Focus | Flexibility & modularity | Productivity & convention-over-configuration |
Use Case | Large enterprise apps needing fine-grained control | Microservices, REST APIs, cloud-native apps |
Example — Building a Simple REST API
(A) Using Spring Framework
Steps:
-
Configure
DispatcherServlet
inweb.xml
. -
Set up Spring Beans in
applicationContext.xml
. -
Configure Tomcat/Jetty server.
-
Create Controller.
<!-- web.xml -->
<web-app>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
<!-- web.xml -->
<web-app>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
@Controller
public class HelloController {
@RequestMapping("/hello")
@ResponseBody
public String sayHello() {
return "Hello from Spring!";
}
}
Needs external Tomcat, WAR deployment.
(B) Using Spring Boot
Steps:
-
Add
spring-boot-starter-web
dependency. -
Write Controller.
-
Run the app.
@SpringBootApplication
public class HelloApp {
public static void main(String[] args) {
SpringApplication.run(HelloApp.class, args);
}
}
@RestController
public class HelloController {
@GetMapping("/hello")
public String sayHello() {
return "Hello from Spring Boot!";
}
}
Just run → http://localhost:8080/hello
works immediately. No XML. No server setup.
When to Use What?
-
Use Spring Framework when:
-
You need fine-grained control over every bean and configuration.
-
You’re working on large legacy enterprise systems that still follow WAR deployment.
-
You want flexibility over conventions.
-
-
Use Spring Boot when:
-
You want rapid development (REST APIs, microservices).
-
You’re deploying to cloud-native environments (Docker, Kubernetes).
-
You want production-ready features out of the box.
-
Conclusion
-
Spring = Foundation (powerful but configuration-heavy).
-
Spring Boot = Accelerator (removes boilerplate, adds auto-magic).
-
Spring Boot saves time, reduces errors, and is ideal for modern cloud-based apps.
-
Example proves: Boot = 5 lines of code vs. Spring = multiple XMLs + configs.
Think of Spring as the “engine” and Spring Boot as the “car”. You can build your own car from scratch with just the engine (Spring), but Boot gives you a ready-to-drive car.