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,
mainends 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;
@Transactionalcommits 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.
The shortcut
When deciding whether Spring earns its place, ask "How much of this app is plumbing?" A long-lived service with HTTP, a database, security and monitoring is mostly plumbing, so Spring pays for itself. A ten-line script that renames files has no plumbing, so Spring adds nothing but weight.
List the needs
REST endpoints, JSON, a database, transactions, logins, health checks for the hosting platform.
A second benefit is easy to miss: because Spring hands each object its dependencies, a test can hand it fakes instead. new LoanService(fakeRepository) works in a plain unit test with no server running.
Drills
Answer fast — trust the rule.
What is the main reason teams choose Spring for a web service?
Which job would Spring not take off your hands in library-service?
Which is a genuine cost of using Spring Boot?
Why does Spring make LoanService easy to unit test?
Remember
- Spring takes the plumbing so your code can be about the problem.
- Ask "how much of this app is plumbing?" Lots means Spring pays off; none means it is overkill.
- Trap: forgetting the costs — startup time, memory, and behaviour hidden behind conventions.
