Lecture 37: Request Body, Path Variable & Request Parameter

BMC201 - Web Technology

Mr. Prashant Kumar Nag

2026-03-25

Lecture 37

Request Body, Path Variable & Request Parameter

Week 10 | Unit V: Spring Boot & REST Services
BMC201 - Web Technology
Mr. Prashant Kumar Nag, Assistant Professor

Session Goals


  • Revise all essential Spring Core concepts from Unit IV
  • Connect IoC, DI, AOP, and bean lifecycle in one flow
  • Build a mini layered app (controller -> service -> repository)
  • Practice debugging common Spring configuration mistakes
  • Prepare for end-sem practical and viva questions

Prerequisites


Before this lecture, quickly revise:

  • previous lecture concepts and key terminology
  • related unit outcomes and expected practical skills
  • baseline Java/web flow needed for in-class examples

Syllabus Mapping


  • Unit alignment for this lecture topic
  • Exam alignment for short and long questions
  • Lab/practical alignment for implementation tasks

Agenda


  • quick revision of context
  • concept explanation with examples
  • implementation/demo walk-through
  • debugging and exam-focused recap

Introduction


This lecture builds conceptual clarity first, then connects it to practical coding and exam application.

Think About It


What one real classroom/lab scenario best demonstrates where this topic is useful?

Spring Core Revision Map


flowchart LR
  A[IoC Container] --> B[Dependency Injection]
  B --> C[Bean Scopes]
  C --> D[Bean Lifecycle]
  D --> E[AOP]
  E --> F[Layered Architecture]
  F --> G[Hands-on Mini App]

Think in terms of responsibilities: container manages, beans execute, aspects monitor.

IoC and DI Recap


IoC: Spring controls object creation and wiring.
DI: Dependencies are provided to classes from outside.

Injection Type Pros Caution
Constructor Clear dependencies, testable, immutable Large constructors can become verbose
Setter Optional dependency support Object can be partially configured
Field Minimal code Hard to test, hidden dependency

Mini App Setup


@SpringBootApplication
public class DemoApp {
  public static void main(String[] args) {
    SpringApplication.run(DemoApp.class, args);
  }
}

@RestController
@RequestMapping("/api/tasks")
public class TaskController {
  private final TaskService service;
  public TaskController(TaskService service) { this.service = service; }
}

Layered Architecture Recap


flowchart TD
  A[Controller] --> B[Service]
  B --> C[Repository]
  C --> D[Database]

  • Controller: request/response handling
  • Service: business rules
  • Repository: data access
  • Keep logic out of controllers for maintainability

Bean Scope Choice in Practice


Choose scope by state behavior:

  • singleton: stateless services (TaskService, validators)
  • prototype: short-lived object with independent state
  • request: per-request context, tracing info
  • session: shopping cart, logged-in preferences

Note

Avoid mutable shared state in singleton beans.

Lifecycle Hook Recap


@Component
public class CacheWarmup {

  @PostConstruct
  public void init() {
    System.out.println("Cache initialized");
  }

  @PreDestroy
  public void shutdown() {
    System.out.println("Cache shutdown");
  }
}

AOP Logging Aspect


@Aspect
@Component
public class TimingAspect {
  @Around("execution(* com.example.service.*.*(..))")
  public Object profile(ProceedingJoinPoint pjp) throws Throwable {
    long start = System.currentTimeMillis();
    Object result = pjp.proceed();
    System.out.println(pjp.getSignature() + " took " +
      (System.currentTimeMillis() - start) + "ms");
    return result;
  }
}

Common Debug Checklist


  • Bean not found: check @ComponentScan package boundaries
  • Ambiguous bean: use @Qualifier or @Primary
  • AOP not applied: verify proxy creation (@EnableAspectJAutoProxy in non-Boot)
  • @PreDestroy not called: ensure context closes gracefully
  • Circular dependency: refactor to constructor + interface separation

Hands-on Task


Build a mini TODO module:

  1. Add TaskController, TaskService, TaskRepository
  2. Use constructor injection in all classes
  3. Add one AOP timing aspect for service methods
  4. Add one bean with @PostConstruct/@PreDestroy
  5. Test endpoint /api/tasks

Exam-Oriented Questions


Prepare:

  1. Explain IoC and DI with examples
  2. Compare constructor and setter injection
  3. Explain bean lifecycle and callbacks
  4. Draw layered architecture for Spring app
  5. Explain practical use of AOP in one real scenario

Summary


  • Spring Core concepts are interconnected, not isolated
  • Unit IV mastery makes Unit V implementation easier
  • Strong architecture and clean DI improve marks and maintainability
  • Hands-on coding is the best revision strategy before exam

Memory Booster


Quick memory anchor for this lecture:

  • define the core concept in one line
  • map where it is used in architecture
  • recall one implementation or exam-style example

Live Demo


Demo focus for this lecture:

  • walk through one practical code flow
  • identify key configuration/code lines
  • verify output and common failure points

Resources & References


  • Official Spring/JSP/Servlet documentation relevant to this lecture
  • Classroom notes and examples discussed in slides
  • Course repository examples and demo references

Structured Debug Checklist


  1. verify imports, annotations/tags, and object names are correct
  2. check request flow, mappings, and lifecycle/state assumptions
  3. inspect runtime logs and stack trace for first failing point
  4. validate expected output against actual response/view

Exam Preparation Questions: Short


  • Define the core concept covered in this lecture.
  • Differentiate related terms/approaches with one example.
  • List important components, annotations, or lifecycle steps.
  • Mention common mistakes and how to avoid them.

Exam Preparation Questions: Long


  • Explain the lecture topic with architecture/flow diagram and examples.
  • Compare alternatives and justify best-practice usage.
  • Discuss practical implementation steps and debugging strategy.

Practice Task


  • implement one minimal, working example based on this lecture
  • test with valid and invalid inputs
  • document two errors encountered and how you fixed them

Checklist


Can you:

  • explain the concept clearly without notes?
  • implement the basic example end-to-end?
  • debug common classroom/exam mistakes?

Next Lecture


  • Topic: Lecture 38 continuation
  • Preparation required: revise this lecture summary and practice task

Request Body, Path Variable & Request Parameter

Next: Lecture 38 - Spring Boot Configuration, Annotations & Build Systems