Skip to the workspace
Pebellslearn by building
Meet Spring  ›  Lesson

Why Use Spring?

Why use Spring? 10 minSpring handles the common plumbing of a server, such as wiring, HTTP, transactions and security, so the code you write is about the business problem.

spring boot / Why Use Spring?

Explore each scene at your own pace.

01 · The rule

The rule

Why Use Spring?

You could write library-service in plain Java: open a socket, parse HTTP by hand, create every object with new, manage database connections yourself. It would take weeks before you wrote a single line about books. Spring exists so that those weeks go into the part only you can write.

The rule

Spring takes the plumbing so your code can be about the problem.

"Plumbing" is everything every server needs but no customer ever asks for:

  • Wiring objects together. Without Spring, main ends up building the whole object graph by hand: new BookController(new LoanService(new BookRepository(dataSource))), and every change ripples through it. Spring does this wiring for you.
  • HTTP and JSON. Spring MVC turns a request into a method call and a Java object into JSON.
  • Data access and transactions. Spring Data writes common queries for you; @Transactional commits or rolls back.
  • Security, metrics, health checks. Each arrives as a starter instead of a project.

Spring Boot adds the last mile: an embedded server, sensible defaults, and a single runnable jar.

@Service
class LoanService {
    private final BookRepository books;
    LoanService(BookRepository books) { this.books = books; }

    @Transactional
    Loan borrow(long bookId, long memberId) { /* only library rules here */ }
}

Look at what is missing: no connection handling, no commit or rollback code, no object creation. What remains is the library's logic.

There are costs, and a good engineer names them. Spring apps start more slowly than a tiny hand-written program, use more memory, and do work "behind the scenes" that can confuse a beginner when something goes wrong. For a short script or a small command-line tool, Spring is often too much.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.