Skip to main content
PreparationZone Logo
PrepZone

Spring, IoC, and Why Boot Exists

The Spring ecosystem, inversion of control, and how Boot removes boilerplate.

Pass checkpoint below

Why this matters

  • "Spring" and "Spring Boot" are not interchangeable — interviews and job postings use both, and conflating them signals shallow knowledge.
  • The ecosystem has distinct projects (MVC, Data, Security) that Boot activates via starters; knowing the map helps you find documentation quickly.
  • Inversion of control is the architectural idea behind every @Autowired and @Bean in the BookStore API.

Spring vs Spring Boot

L1 · Fresher

Spring Framework provides IoC, MVC, Data, Security, and more. Spring Boot adds auto-configuration, starters, and embedded servers so BookStore boots with minimal XML or Java config.

Inversion of control in one sentence

L2 · Intermediate

You declare components; the container creates them and injects dependencies. Boot's @SpringBootApplication enables component scan and auto-config on the classpath.

Spring projects you still touch in Boot

L3 · Advanced

Spring Data JPA, Spring Security, and Spring MVC are libraries inside Boot — not separate servers. Knowing which layer owns a bug (MVC vs Data vs Security) speeds up fixes.

When plain Spring still wins

L4 · Expert

Non-Boot deployments on external Tomcat, heavy XML legacy, or custom classloader environments may skip Boot. Interview answer: Boot optimizes the default path; Spring remains the core programming model.

ApplicationContext
BookController@RestController
BookService@Service
BookRepository@Repository
DataSourceAuto-configured

Arrows show @Autowired wiring — container injects at startup

The ApplicationContext reads configuration, creates beans, and wires dependencies automatically.

The Spring portfolio

Projects you will touch in BookStore

  • Spring Framework — Core IoC container, AOP, transaction abstraction, and MVC web layer.
  • Spring Boot — Auto-configuration, embedded server, production-ready defaults, and the starter ecosystem.
  • Spring Data JPA — Repository abstraction over Hibernate for Book and Author entities.
  • Spring Security — Authentication, authorization, and the filter chain protecting /api/**.
  • Springdoc OpenAPI — Generates Swagger UI from your controller annotations.

Inversion of control explained

In a traditional BookStore app you might write:

Java
public class BookController {
    private final BookService bookService = new BookService(
        new JdbcBookRepository(new DataSource(/* url, credentials */))
    );
}

Every class constructs its own dependencies. Changing the repository implementation means editing every caller.

Spring inverts this: the container creates objects and injects dependencies. You declare what you need; Spring figures out how to provide it.

Java
// learn:fragment
@RestController
public class BookController {
    private final BookService bookService;

    public BookController(BookService bookService) {
        this.bookService = bookService;  // injected by Spring
    }
}

The controller never calls new BookService(). The container does at startup.

ApplicationContext: the heart of Spring

The ApplicationContext is a registry of beans — objects Spring manages. At startup it:

Container startup steps

  1. Scans for @Component, @Service, @Repository, @Controller.
  2. Reads @Configuration classes and @Bean methods.
  3. Resolves constructor dependencies and creates instances.
  4. Applies @PostConstruct callbacks and registers shutdown hooks.

For BookStore, a single context holds one BookService, one BookRepository, and one DataSource — shared across all requests.

Advantages and disadvantages

AdvantagesWhat you gain in BookStoreDisadvantagesWhat it costs
Auto-configurationDataSource, Jackson, and Tomcat appear because the starter is on the classpathHidden behaviourA bean exists that you did not write, and the condition that created it is easy to miss
Starters and the BOMOne dependency, versions that work togetherOpinionated stackReplacing Tomcat or the JSON library means excluding transitive modules
Embedded server`java -jar` is the whole deployFat JARLarger images and a server you configure with properties instead of server.xml
Production defaultsActuator, externalised config, sensible error pagesStartup and memoryComponent scan and auto-config do more work than a hand-built context
Fast path to a featureA CRUD API in one moduleMagic during outagesYou still need to know the filter chain, proxies, and property order when defaults are wrong
  • Auto-configuration

    What you gain in BookStoreDataSource, Jackson, and Tomcat appear because the starter is on the classpath
    DisadvantagesHidden behaviour
    What it costsA bean exists that you did not write, and the condition that created it is easy to miss
  • Starters and the BOM

    What you gain in BookStoreOne dependency, versions that work together
    DisadvantagesOpinionated stack
    What it costsReplacing Tomcat or the JSON library means excluding transitive modules
  • Embedded server

    What you gain in BookStore`java -jar` is the whole deploy
    DisadvantagesFat JAR
    What it costsLarger images and a server you configure with properties instead of server.xml
  • Production defaults

    What you gain in BookStoreActuator, externalised config, sensible error pages
    DisadvantagesStartup and memory
    What it costsComponent scan and auto-config do more work than a hand-built context
  • Fast path to a feature

    What you gain in BookStoreA CRUD API in one module
    DisadvantagesMagic during outages
    What it costsYou still need to know the filter chain, proxies, and property order when defaults are wrong

Boot is the right default for a new BookStore service. It is a poor fit when you must deploy a WAR onto an application server the platform team already runs, or when a tiny library should not start an embedded container. In those cases use Spring Framework without the Boot launcher.

Why Boot exists

Plain Spring required extensive XML or Java configuration:

Java
// learn:fragment
@Configuration
public class WebConfig {
    @Bean
    public DispatcherServlet dispatcherServlet() { ... }
    @Bean
    public DataSource dataSource() { ... }
    // dozens more beans
}

Boot's auto-configuration detects classpath contents and configures beans conditionally. Add spring-boot-starter-data-jpa and a DataSource appears when application.yml has a spring.datasource.url.

Spring vs Spring Boot responsibilities

AspectSpring FrameworkSpring Boot
Dependency injectionYesUses Framework
MVC mappingYesAuto-registers DispatcherServlet
Embedded TomcatNoYes
Externalised configBasic supportapplication.yml, profiles, @ConfigurationProperties
Production metricsManual setupActuator starters
  • Dependency injection

    Spring FrameworkYes
    Spring BootUses Framework
  • MVC mapping

    Spring FrameworkYes
    Spring BootAuto-registers DispatcherServlet
  • Embedded Tomcat

    Spring FrameworkNo
    Spring BootYes
  • Externalised config

    Spring FrameworkBasic support
    Spring Bootapplication.yml, profiles, @ConfigurationProperties
  • Production metrics

    Spring FrameworkManual setup
    Spring BootActuator starters

Boot does not replace Spring — it configures it.

The starter pattern preview

Instead of listing twenty JAR coordinates, Boot offers curated bundles:

Java
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
</dependency>

One dependency brings Tomcat, Jackson, Spring MVC, and validation. The starters module covers this in depth.

Jakarta EE namespace shift

Spring Boot 3.x runs on Jakarta EE 9+ packages (jakarta.servlet, jakarta.persistence). Code using javax.* imports from older tutorials will not compile. When reading Stack Overflow answers, check the Spring Boot version.

Ecosystem versioning

Spring Boot 3.5.x aligns with Spring Framework 6.x and requires Java 21+. The Spring release train publishes compatible versions together. Stick to the BOM — mixing manual version overrides causes subtle runtime failures.

Where BookStore fits

Your learning path builds the BookStore API layer by layer: web foundations → IoC wiring → Boot auto-config → REST endpoints → JPA persistence → cross-cutting concerns → security. Each module adds one Spring project to the same application.

Java
Loading compiler…

That single annotation bootstraps the entire ecosystem for your app.

Quick recall

Everything you need if you only revisit this box.

  • Spring Framework provides IoC, MVC, AOP, and transactions; Boot auto-configures them.
  • Inversion of control means the container creates and wires objects — you declare dependencies, not construction.
  • ApplicationContext is the bean registry created at startup and shared across requests.
  • Boot 3.x uses Jakarta (jakarta.*) packages and requires Java 21+.
  • Boot's advantages are auto-configuration, starters, an embedded server, and production defaults.
  • The cost is hidden beans, a fatter deployable, and defaults you must know how to override.
  • Starters bundle related dependencies; the BOM keeps versions compatible.
  • BookStore grows through the track by adding one Spring concern per module.

Test yourself

Answer these before moving on — recall is what makes it stick.

Checkpoint quiz

Pass 6 of 9 to verify this article on your path — scrolling alone does not count.

Question 1 of 9

BookStore on-call: a junior says "Spring vs Spring Boot" is only theory. What do you correct them with?