Skip to lesson

Spring Framework vs Spring Boot

ShopLite needs a web server, JSON conversion and logging, all working together. Choosing and connecting each library by hand would take days before the first endpoint answers. Spring Boot exists to remove that setup.

Spring Framework: the container and its modules

The Spring Framework is a set of Java libraries built around a dependency injection container, plus modules for the web, databases and transactions.

Example 1 uses only the container: one dependency, no web server. main asks it for a ready-wired OrderService.

Example 1 · src/main/java/com/shoplite/demo/PlainSpringApp.java

Runs in: a plain Maven project with spring-context 7.0

PlainSpringApp.javaJava
package com.shoplite.demo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;
interface Notifier {    void send(String to, String message);}
class EmailNotifier implements Notifier {    public void send(String to, String message) {        System.out.println("EMAIL to " + to + ": " + message);    }}
class OrderService {    private final Notifier notifier;
    OrderService(Notifier notifier) {        this.notifier = notifier;    }
    void placeOrder(int orderId, String email) {        notifier.send(email, "Your order " + orderId + " is confirmed");    }}
// Recipes for the Spring container, one method per object@Configurationclass AppConfig {    @Bean    Notifier notifier() {        return new EmailNotifier();    }
    @Bean    OrderService orderService(Notifier notifier) {   // Spring passes in the Notifier it made        return new OrderService(notifier);    }}
public class PlainSpringApp {    public static void main(String[] args) {        try (AnnotationConfigApplicationContext context =                     new AnnotationConfigApplicationContext(AppConfig.class)) {            OrderService orders = context.getBean(OrderService.class);            orders.placeOrder(601, "asha@example.com");
            System.out.println("Same object again? " + (orders == context.getBean(OrderService.class)));        }    }}
Output
EMAIL to asha@example.com: Your order 601 is confirmed
Same object again? true

What this code does

  • The project's pom.xml has one dependency, org.springframework:spring-context 7.0.9, plus the exec-maven-plugin so mvn compile exec:java runs this class. No parent, no starter, no web server.
  • AppConfig gives Spring one @Bean method per object. For orderService(Notifier notifier), Spring passes in the Notifier made by the other method: dependency injection.
  • getBean(OrderService.class) returns the same wired object both times, like MiniContainer. The try (...) closes the context, so Spring shuts its beans down cleanly.

The container (Spring calls it the application context) is the core, and each module plugs into it as a separate jar you can use or leave out. The @Configuration class holds one @Bean method per object, which is the grown-up version of MiniContainer's recipes; the next module explains these annotations properly.

The main modules:

  • Core container (spring-context): creates, wires and manages objects, which Spring calls beans.
  • Web MVC (spring-webmvc): maps HTTP requests to your controller methods and turns results into JSON.
  • JDBC support (spring-jdbc): JdbcTemplate and JdbcClient remove the connection and try boilerplate of Section 13.
  • Transactions (spring-tx): @Transactional starts, commits and rolls back database transactions for you.
What can go wrong without Boot: you choose every library and its version yourself, set up the web server, logging and JSON yourself, and make sure all of them work together.

Spring Boot: starters, auto-configuration and an embedded server

Spring Boot is a project that sets up the Spring Framework for you with sensible choices, so you write your own code instead of setup code.

Example 2 lists what one starter brings. Example 3 starts an app with no server code that still runs Tomcat.

Four layers from top to bottom: your ShopLite code, then Spring Boot (starters, auto-configuration, embedded Tomcat, defaults), then the Spring Framework (container, Web MVC, JDBC support, transactions), then Java 17. Boot sets up the Framework for you; it does not replace it.

Example 2 · What one Boot starter brings: mvnw dependency:tree

Runs in: the shoplite-api Spring Boot project

Terminal
mvnw dependency:tree -Dscope=compile
Sample output
[INFO] Loaded 74 auto-discovered prefixes for remote repository apache.snapshots (prefixes-apache.snapshots.txt)
[INFO] com.shoplite:shoplite-api:jar:0.0.1-SNAPSHOT
[INFO] \- org.springframework.boot:spring-boot-starter-webmvc:jar:4.1.1:compile
[INFO]    +- org.springframework.boot:spring-boot-starter:jar:4.1.1:compile
[INFO]    |  +- org.springframework.boot:spring-boot-starter-logging:jar:4.1.1:compile
[INFO]    |  |  +- ch.qos.logback:logback-classic:jar:1.5.38:compile
[INFO]    |  |  |  \- ch.qos.logback:logback-core:jar:1.5.38:compile
[INFO]    |  |  +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.25.5:compile
[INFO]    |  |  |  \- org.apache.logging.log4j:log4j-api:jar:2.25.5:compile
[INFO]    |  |  \- org.slf4j:jul-to-slf4j:jar:2.0.18:compile
[INFO]    |  +- org.springframework.boot:spring-boot-autoconfigure:jar:4.1.1:compile
[INFO]    |  +- jakarta.annotation:jakarta.annotation-api:jar:3.0.0:compile
[INFO]    |  \- org.yaml:snakeyaml:jar:2.6:compile
[INFO]    +- org.springframework.boot:spring-boot-starter-jackson:jar:4.1.1:compile
[INFO]    |  \- org.springframework.boot:spring-boot-jackson:jar:4.1.1:compile
[INFO]    |     \- tools.jackson.core:jackson-databind:jar:3.1.5:compile
[INFO]    |        +- com.fasterxml.jackson.core:jackson-annotations:jar:2.21:compile
[INFO]    |        \- tools.jackson.core:jackson-core:jar:3.1.5:compile
[INFO]    +- org.springframework.boot:spring-boot-starter-tomcat:jar:4.1.1:compile
[INFO]    |  +- org.springframework.boot:spring-boot-starter-tomcat-runtime:jar:4.1.1:compile
[INFO]    |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:11.0.24:compile
[INFO]    |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:11.0.24:compile
[INFO]    |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:11.0.24:compile
[INFO]    |  \- org.springframework.boot:spring-boot-tomcat:jar:4.1.1:compile
[INFO]    +- org.springframework.boot:spring-boot-http-converter:jar:4.1.1:compile
[INFO]    |  +- org.springframework.boot:spring-boot:jar:4.1.1:compile
[INFO]    |  |  \- org.springframework:spring-context:jar:7.0.9:compile
[INFO]    |  \- org.springframework:spring-web:jar:7.0.9:compile
[INFO]    |     +- org.springframework:spring-beans:jar:7.0.9:compile
[INFO]    |     \- io.micrometer:micrometer-observation:jar:1.17.1:compile
[INFO]    |        \- io.micrometer:micrometer-commons:jar:1.17.1:compile
[INFO]    \- org.springframework.boot:spring-boot-webmvc:jar:4.1.1:compile
[INFO]       +- org.springframework.boot:spring-boot-servlet:jar:4.1.1:compile
[INFO]       \- org.springframework:spring-webmvc:jar:7.0.9:compile
[INFO]          +- org.springframework:spring-aop:jar:7.0.9:compile
[INFO]          \- org.springframework:spring-expression:jar:7.0.9:compile

What this code does

  • The project lists one dependency, spring-boot-starter-webmvc. Under it come Spring Web MVC 7.0.9, embedded Tomcat 11.0.24, Jackson 3.1.5 and Logback for logging.
  • spring-context appears inside the tree: the Spring Framework container is still underneath. spring-boot-autoconfigure is the part that does the automatic setup.
  • Run it in the shoplite-api folder from the next lesson (.\mvnw in PowerShell, ./mvnw on macOS). Maven's header and footer lines are left out here.

Example 3 · Auto-configuration at work: a web server nobody configured

Runs in: the shoplite-api Spring Boot project

Terminal
mvnw spring-boot:run
Sample output
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/

 :: Spring Boot ::                (v4.1.1)

2026-10-16T08:32:38.075+05:30  INFO 6460 --- [shoplite-api] [           main] com.shoplite.ShopliteApiApplication      : Starting ShopliteApiApplication using Java 19.0.2 with PID 6460 (C:\Users\asha\shoplite-api\target\classes started by asha in C:\Users\asha\shoplite-api)
2026-10-16T08:32:38.085+05:30  INFO 6460 --- [shoplite-api] [           main] com.shoplite.ShopliteApiApplication      : No active profile set, falling back to 1 default profile: "default"
2026-10-16T08:32:42.384+05:30  INFO 6460 --- [shoplite-api] [           main] o.s.boot.tomcat.TomcatWebServer          : Tomcat initialized with port 8080 (http)
2026-10-16T08:32:42.479+05:30  INFO 6460 --- [shoplite-api] [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2026-10-16T08:32:42.480+05:30  INFO 6460 --- [shoplite-api] [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/11.0.24]
2026-10-16T08:32:43.195+05:30  INFO 6460 --- [shoplite-api] [           main] b.w.c.s.WebApplicationContextInitializer : Root WebApplicationContext: initialization completed in 5002 ms
2026-10-16T08:32:44.803+05:30  INFO 6460 --- [shoplite-api] [           main] o.s.boot.tomcat.TomcatWebServer          : Tomcat started on port 8080 (http) with context path '/'
2026-10-16T08:32:44.826+05:30  INFO 6460 --- [shoplite-api] [           main] com.shoplite.ShopliteApiApplication      : Started ShopliteApiApplication in 8.786 seconds (process running for 13.588)
2026-10-16T08:32:46.408+05:30  INFO 6460 --- [shoplite-api] [io-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2026-10-16T08:32:46.416+05:30  INFO 6460 --- [shoplite-api] [io-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2026-10-16T08:32:46.425+05:30  INFO 6460 --- [shoplite-api] [io-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 9 ms

What this code does

  • The project has one Java class and one line in application.properties, yet the log shows Tomcat 11.0.24 started on port 8080. Auto-configuration saw Tomcat on the classpath and set it up with Boot's default port.
  • [shoplite-api] in every line comes from spring.application.name. Times, the process id (PID) and paths differ on your computer.

Boot adds four things:

  • Starter: one dependency that brings a tested set of libraries. spring-boot-starter-webmvc brings Spring Web MVC, Tomcat, Jackson for JSON and logging, in versions known to work together.
  • Auto-configuration: looks at what is on the classpath and creates the beans you would otherwise write by hand. Tomcat is there, so it starts a web server; Jackson is there, so JSON conversion is ready.
  • Embedded server: Tomcat runs inside your application, so java -jar shoplite-api.jar is the whole deployment.
  • Defaults: values such as port 8080 work until you change them in application.properties.

Boot does not replace the Framework. Every Boot app is a Spring Framework app, and Boot only removes the setup work. If something is missing, you can add your own bean, and Boot steps back.

Interview angle: "Spring Boot is Spring Framework plus starters, auto-configuration, an embedded server and defaults. It is not a different framework."

The wider family: Spring Data, Spring Security, Spring Cloud

Around the Framework and Boot sit more Spring projects, each solving one big problem. With Boot you add each one by adding its starter, such as spring-boot-starter-data-jpa or spring-boot-starter-security; auto-configuration does the rest.

The course uses three of them later: Spring Data JPA in Section 16, Spring Security in Section 17, and Spring Boot Actuator for health checks later in this section. Spring Cloud is for systems made of many small services and is beyond this course.

  • Spring Data: repositories where you write an interface and Spring writes the query code.
  • Spring Security: login, passwords, roles and tokens for your endpoints.
  • Spring Cloud: tools for many services talking to each other (configuration servers, service discovery).

Versions used in this course

Example 4 shows which Java Maven uses, because Spring Boot 4 needs Java 17 or newer.

Example 4 · Which Java does Maven use? mvnw -v

Runs in: the shoplite-api Spring Boot project

Terminal
mvnw -v
Sample output
Apache Maven 3.10.0 (c43a36b8d67be7e0805a411bc0898af1a51f5472)
Maven home: C:\Users\asha\.m2\wrapper\dists\apache-maven-3.10.0\2aaba761688b1a6ea5a46e7e5f4d5406ed7a75ee8da95e5e3079863a23461c9b
Java version: 19.0.2, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-19
Default locale: en_IN, platform encoding: UTF-8, time zone: Asia/Calcutta
OS name: "windows 11", version: "10.0", arch: "amd64", family: "windows"

What this code does

  • Java version is the JDK Maven will compile with. It must be 17 or newer for Spring Boot 4; this computer has JDK 19.
  • The first line is the Maven version that the wrapper (mvnw) downloaded for this project. Paths and versions differ on your computer.

Spring versions matter because a major version changes package names and removes old features. This course uses Spring Boot 4.1 with Spring Framework 7, Jakarta EE 11 (Servlet 6.1 in Tomcat 11) and Java 17 or newer; Boot 4.1.1 was current when this section was written. You set only two versions yourself, <version>4.1.1</version> in the spring-boot-starter-parent block and <java.version>17</java.version>, and Boot's parent picks matching versions for everything else, which is why the dependencies in a Boot pom.xml usually have no <version> tag.

Versions to know:

  • Spring Boot 4.1.1 brings Spring Framework 7.0.9 and Tomcat 11.0.24.
  • JSON uses Jackson 3, whose classes live in tools.jackson.*, not the older com.fasterxml.jackson.databind.
  • Old tutorials (Spring Boot 2.x, Java 8 or 11) still show up first in searches. Check the version before copying code.

javax to jakarta: why old tutorials' imports do not compile

Jakarta EE is the set of standard Java APIs for servers, such as servlets, validation and persistence; since Spring Boot 3 its packages start with jakarta., not javax..

Example 5 compiles code copied from an old tutorial and fails. Example 6 is the same class with the imports fixed.

Example 5 · Old tutorial code: javax imports on Spring Boot 4

Runs in: the shoplite-api Spring Boot project

ClientInfoController.javaJava
package com.shoplite.hello;
import javax.annotation.PostConstruct;import javax.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RestController;
// Copied from an old (Spring Boot 2) tutorial@RestControllerpublic class ClientInfoController {
    @PostConstruct    void ready() {        System.out.println("ClientInfoController is ready");    }
    @GetMapping("/client-info")    public String clientInfo(HttpServletRequest request) {        return "You called " + request.getRequestURI() + " using " + request.getMethod();    }}
Sample compiler output
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/asha/shoplite-api/src/main/java/com/shoplite/hello/ClientInfoController.java:[3,24] package javax.annotation does not exist
[ERROR] /C:/Users/asha/shoplite-api/src/main/java/com/shoplite/hello/ClientInfoController.java:[4,26] package javax.servlet.http does not exist
[ERROR] /C:/Users/asha/shoplite-api/src/main/java/com/shoplite/hello/ClientInfoController.java:[19,30] cannot find symbol
  symbol:   class HttpServletRequest
  location: class com.shoplite.hello.ClientInfoController
[ERROR] /C:/Users/asha/shoplite-api/src/main/java/com/shoplite/hello/ClientInfoController.java:[13,6] cannot find symbol
  symbol:   class PostConstruct
  location: class com.shoplite.hello.ClientInfoController
[INFO] 4 errors

What this code does

  • This is the real Maven compiler output. [3,24] means line 3, column 24: the javax.annotation import. Every later error comes from those two bad imports.
  • Boot 4 ships jakarta.annotation and jakarta.servlet, so the javax packages simply are not on the classpath. Adding an old javax library to the pom does not help: Spring would not use it.

Example 6 · The fix: the same class with jakarta imports

Runs in: the shoplite-api Spring Boot project

ClientInfoController.javaJava
package com.shoplite.hello;
import jakarta.annotation.PostConstruct;import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RestController;
// Fixed for Spring Boot 4: javax.* became jakarta.*@RestControllerpublic class ClientInfoController {
    @PostConstruct    void ready() {        System.out.println("ClientInfoController is ready");    }
    @GetMapping("/client-info")    public String clientInfo(HttpServletRequest request) {        return "You called " + request.getRequestURI() + " using " + request.getMethod();    }}
Sample output (curl -i http://localhost:8080/client-info)
HTTP/1.1 200 
Content-Type: text/plain;charset=UTF-8
Content-Length: 33
Date: Fri, 16 Oct 2026 03:00:03 GMT

You called /client-info using GET

What this code does

  • Only the two import lines changed. The class names PostConstruct and HttpServletRequest are the same.
  • The app now compiles and starts, ClientInfoController is ready appears in the startup log, and the endpoint answers with status 200.

Jakarta EE used to be called Java EE and lived in packages starting with javax.. When it moved to the Eclipse Foundation the packages were renamed to jakarta., so code copied from a Spring Boot 2 tutorial fails with package javax.servlet.http does not exist. Change the package in the import; the class names stay the same, and your IDE's "Optimize imports" often finds the new package once the old import is deleted. Not every javax. package moved: javax.sql.DataSource and javax.crypto are part of the JDK itself and keep their names.

The common renames:

  • javax.servlet.* → jakarta.servlet.*
  • javax.validation.* → jakarta.validation.*
  • javax.persistence.* → jakarta.persistence.*
  • javax.annotation.PostConstruct → jakarta.annotation.PostConstruct

Fix the error

Fix the old import

Pick the replacement for the line that fails on Spring Boot 4.

Round 1 of 2

A controller copied from an old tutorial does not compile.

import javax.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

Error

error: package javax.servlet.http does not exist

Next step

Check your understanding

12 quick questions