Introduction to Spring Framework
Spring Framework is an open-source application platform for the Java ecosystem.
Introduction
Spring Framework is an open-source application platform for the Java ecosystem. Think of it as the operating system for your business code: it wires your objects together, manages their lifecycle, handles transactions, web requests, security and database access — so you can focus on the parts that make your product unique.
Before Spring (and the broader era of lightweight Java), enterprise apps were built on heavy J2EE servers where every class had to extend framework-specific base classes. Spring flipped that idea: your code stays plain Java (POJOs), and Spring adds the plumbing around it through configuration. That single shift is why Spring became the default backbone of Java backends.
This course teaches you the framework itself — the engine that powers Spring Boot, Spring Cloud, and almost every modern Java service. By the end you will be able to read any Spring codebase fluently, debug bean wiring problems, design clean service layers, and decide which Spring module fits a given problem.
Understanding the topic
What Spring actually gives you:
- 🧠 An IoC container that creates and connects your objects (called beans).
- 💉 Dependency Injection so classes ask for what they need instead of building it.
- 🎯 AOP (Aspect-Oriented Programming) for cross-cutting concerns like logging, security, transactions.
- 🌐 Spring MVC for building web apps and REST APIs.
- 🗃️ Spring Data / JDBC / ORM for clean, transactional database access.
- 🧩 Strong integration modules: messaging, scheduling, caching, validation, testing.
- 🛡️ Spring Security for authentication, authorization and protection against common web attacks.
- 🧪 A first-class testing framework that lets you load only the slice of the app you care about.
The big idea in one sentence: you describe what your application is made of, and Spring takes care of how those parts are built, connected and managed at runtime.
Syntax reference
Where Spring sits in a typical Java backend:
┌─────────────────────────────────────────────┐│ Browser / Mobile / Service Client │├─────────────────────────────────────────────┤│ Spring MVC (Controllers · REST) ││ Spring Security · Validation · AOP ││ Spring Core (IoC Container · Beans) ││ Spring Data / JDBC / TX · Messaging │├─────────────────────────────────────────────┤│ JVM · Application Server / Embedded │└─────────────────────────────────────────────┘
Informative example
A 30-second taste — the same idea twice:
// Without Spring: the class builds its own collaboratorspublic class CheckoutService {private final PaymentGateway gateway = new StripePaymentGateway("sk_test_...");private final InvoiceRepository repo = new JdbcInvoiceRepository(dataSource());// hard to test, hard to swap, hard to configure per environment}// With Spring: the class declares what it needs@Servicepublic class CheckoutService {private final PaymentGateway gateway;private final InvoiceRepository repo;public CheckoutService(PaymentGateway gateway, InvoiceRepository repo) {this.gateway = gateway;this.repo = repo;}}
The second version is easier to test (pass fakes in a constructor), easier to configure (swap the gateway per environment), and easier to reason about (dependencies are explicit). That is the whole pitch of Spring, compressed into eight lines.
Real-world use
Most large Java systems you interact with — bank portals, airline booking engines, e-commerce checkouts, government services, streaming platforms — are built on Spring. The same framework scales from a 200-line side project to platforms running thousands of microservices. Job postings for "backend Java" almost always mean "Spring" in practice.
Best practices
- Start with the core container (beans + DI) before diving into MVC or Data.
- Always model your domain as plain Java classes — let Spring decorate them, not own them.
- Prefer constructor injection: it makes dependencies explicit and easy to test.
- Read the bean lifecycle once; afterwards 80% of "weird Spring behaviour" becomes obvious.
Common mistakes
- Confusing Spring Framework with Spring Boot: Boot is an opinionated layer that auto-configures the framework.
- Treating Spring as magic — every annotation eventually maps to a normal Java call you can step through in a debugger.
- Skipping the core container and jumping straight to MVC — you will struggle to debug wiring later.
Hands-on exercise
Warm-up: create a Maven project and add spring-context as a dependency. Define two classes — a Greeter that says hello, and a GreetingApp that uses it. Wire them with a @Configuration class and load them through an AnnotationConfigApplicationContext. Print the greeting from main. You should not call new Greeter() anywhere outside the config class.