๐Ÿ‡ฎ๐Ÿ‡ณ
๐Ÿ‡ฎ๐Ÿ‡ณ
Limited-Time Offer!Get 20% OFF on all live courses
Enroll Now
PrakalpanaLive online tech training
Java Ecosystemโฑ๏ธ 11 min read๐Ÿ“… Jul 12

Spring Framework Tutorial for Beginners: Core, DI, AOP & MVC (2026)

PM
Priya Menonโ€ขBackend Tech Lead
๐Ÿ“‘ Contents (11 sections)

๐Ÿ“ŒWhy Learn Spring (Not Just Spring Boot)?

Everyone jumps straight to Spring Boot and then gets confused because they never learned what Boot is built *on*. Spring Boot is a convenience layer; the Spring Framework is the engine, its Inversion of Control container, dependency injection, and AOP are what make the whole ecosystem work. Understand these once and Spring Boot, Spring Data, and Spring Security all suddenly make sense.

This tutorial covers the four pillars every beginner needs: the IoC container, dependency injection, AOP, and Spring MVC. When you are ready to go faster, the Spring Boot course and the Spring Boot track build directly on this.

๐Ÿ“ŒPillar 1: Inversion of Control (IoC)

Normally your code creates its own dependencies:

// Tightly coupled, YOU control creation
public class OrderService {
private final PaymentService payment = new UpiPaymentService(); // hardcoded!
}

The problem: OrderService is welded to UpiPaymentService. You cannot swap it, and you cannot unit test with a fake. Inversion of Control flips this, instead of your class creating dependencies, a container creates them and hands them in. The control is *inverted* from your code to the framework.

๐Ÿ“ŒPillar 2: Dependency Injection (DI)

DI is *how* IoC is implemented, the container "injects" dependencies. Prefer constructor injection:

@Service
public class OrderService {
private final PaymentService payment;
// Spring injects the right PaymentService here
public OrderService(PaymentService payment) {
this.payment = payment;
}
public void placeOrder(int amount) {
payment.pay(amount);
}
}

Now OrderService depends on the PaymentService interface, not a concrete class. Swap implementations without editing OrderService, and inject a mock in tests trivially. This single idea is the backbone of testable Java. If interfaces and objects feel shaky, shore them up via the Java course.

๐Ÿ“ŒBeans and the Application Context

A bean is just an object managed by the Spring container. The container, the ApplicationContext, creates beans, wires their dependencies, and manages their lifecycle. You declare beans with stereotype annotations:

  • @Component, a generic Spring-managed bean
  • @Service, business logic
  • @Repository, data access (adds exception translation)
  • @Controller / @RestController, web layer
  • And you tell Spring where to look with configuration:

    @Configuration
    @ComponentScan("com.prakalpana.shop")
    public class AppConfig {
    // An explicitly declared bean
    @Bean
    public PaymentService paymentService() {
    return new UpiPaymentService();
    }
    }
    // Bootstrapping the container manually (what Spring Boot hides from you)
    ApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class);
    OrderService orders = ctx.getBean(OrderService.class);
    orders.placeOrder(500);

    ๐Ÿ“ŒBean Scopes and Lifecycle

    By default beans are singletons, one shared instance per container. Other scopes include prototype (a new instance each time), and web scopes request and session. You can hook into the lifecycle with @PostConstruct and @PreDestroy:

    @Component
    public class CacheWarmer {
    @PostConstruct
    public void init() {
    System.out.println("Bean ready, warming cache...");
    }
    @PreDestroy
    public void cleanup() {
    System.out.println("Container shutting down, flushing cache...");
    }
    }

    ๐Ÿ“ŒPillar 3: Aspect-Oriented Programming (AOP)

    Some concerns, logging, security, transactions, cut *across* many methods. Copying that code everywhere is a mess. AOP lets you write it once as an aspect and apply it declaratively. Key terms: an aspect is the module, a join point is where it can run, a pointcut selects which join points, and advice is the code that runs.

    @Aspect
    @Component
    public class LoggingAspect {
    // Run before every method in the service package
    @Before("execution(* com.prakalpana.shop.service.*.*(..))")
    public void logCall(JoinPoint jp) {
    System.out.println("Calling: " + jp.getSignature().getName());
    }
    }

    This is exactly how @Transactional works under the hood, Spring wraps your method in a proxy that opens and commits a transaction around it. Understanding AOP demystifies a lot of "magic."

    ๐Ÿ“ŒPillar 4: Spring MVC

    Spring MVC is the web layer. A request flows through the DispatcherServlet, which routes it to the right controller method, which returns data (or a view name). The core annotations:

    @RestController
    @RequestMapping("/api/products")
    public class ProductController {
    private final ProductService service;
    public ProductController(ProductService service) {
    this.service = service;
    }
    @GetMapping("/{id}")
    public Product getOne(@PathVariable Long id) {
    return service.findById(id);
    }
    @PostMapping
    public Product create(@RequestBody Product p) {
    return service.save(p);
    }
    }

    @RestController combines @Controller and @ResponseBody, so return values are serialized straight to JSON, no view resolver needed for APIs.

    ๐Ÿ“ŒWhere Spring Boot Fits

    Everything above still needs manual configuration, a servlet container, component scanning, JSON setup. Spring Boot auto-configures all of it and embeds a Tomcat server so you can run a JAR directly. But now you know what it is automating. For the full picture of the difference, read our comparison and then move to the Spring Boot track.

    ๐Ÿ“ŒA Beginner's Learning Order

  • 1IoC and DI, the *why* behind everything
  • 2Beans, scopes, and the ApplicationContext
  • 3AOP, so @Transactional stops being magic
  • 4Spring MVC, controllers and request mapping
  • 5Then Spring Boot, and it will feel easy
  • ๐Ÿ“ŒCommon Beginner Questions

  • @Component vs @Bean? @Component is auto-detected via scanning; @Bean is declared explicitly in a @Configuration class, use it for objects you do not own.
  • Why constructor injection? Immutable, testable, and fails fast if a dependency is missing.
  • Is the container thread-safe? Singleton beans are shared, so keep them stateless.
  • ๐Ÿ“ŒLearn It With a Mentor

    Spring's concepts click fastest when someone explains the *why* and reviews your code live. Prakalpana offers live online and 1-on-1 Spring and Spring Boot training that starts from exactly these fundamentals. WhatsApp or call +91 9945619267 for a free trial session.

    PM

    Written by

    Priya Menon

    Backend Tech Lead

    ๐Ÿš€ Master Java Ecosystem

    Join 5000+ developers

    Explore Courses โ†’