Layered Architecture and Spring Framework

Jul 18, 2024

Layered Architecture and Spring Framework

Layered Architecture

  • Definition: Developing applications with loosely coupled layers.
  • Layers: Presentation Layer, Web Layer, Service Layer, Persistence Layer
    • Presentation Layer: User Interface (e.g., Angular, React)
    • Web Layer: Handles request and response (e.g., Servlets, Struts)
    • Service Layer: Contains business logic (Java or third-party libraries)
    • Persistence Layer: Communicates with the database (e.g., JDBC, Hibernate)

Problems with JDBC

  • Requires a lot of boilerplate code.
  • Hibernate introduced to avoid these problems.

Benefits of Frameworks

  • Provide common logic needed for applications.
  • Developers focus on business logic only.
  • Faster development and reduced code duplication.
  • Easier maintenance with fewer bugs.

Issues with Struts and Hibernate

  • Struts: Framework for the web layer only.
  • Hibernate: Framework for the persistence layer only.
  • Need multiple frameworks for a single application.

Spring Framework

  • Introduction: Comprehensive application development framework.
  • Benefits: Free, Java-based, and supports end-to-end application development.
  • History: Released in 2004, gained popularity from 2010. Current version is 6.x (requires Java 17).
  • Modular: Consists of multiple loosely coupled modules.

Spring Framework Modules

  1. Core Module: Base module providing fundamental concepts (IOC container, Dependency Injection, Auto-wiring).
  2. Context Module: Manages application configurations.
  3. AOP Module: Aspect Oriented Programming for separating primary and secondary logic.
  4. JDBC Module: Facilitates persistence layer development, reduces boilerplate code.
  5. ORM Module: Object Relational Mapping, provides integration with Hibernate.
  6. Web MVC Module: Develops web applications with MVC architecture.
  7. Security Module: Manages authentication and authorization.
  8. Data JPA Module: Simplifies persistence with auto-query generation and reduced boilerplate code.
  9. Additional Modules: Batch, Cloud, Messaging, etc.

Core Concepts in Modules

  • Core Module: IOC container, Dependency Injection, Auto-wiring.
  • Context Module: Configuration management.
  • AOP Module: Separates primary business logic from cross-cutting concerns such as security, transactions, logging, etc.
  • JDBC Module: Eases database interactions by reducing repetitive code.
  • ORM Module: Represents data as objects, integrates seamlessly with Hibernate.
  • Web MVC Module: Supports full web application development within Spring's MVC architecture.
  • Security Module: Provides mechanisms for authentication (who can access) and authorization (what they can access).
  • Data JPA Module: Automates persistence tasks, further reducing the need for manual queries.

Spring Framework Development Approaches

  1. Normal JDBC: Directly uses JDBC API.
  2. Spring JDBC: Uses Spring JDBC to manage common tasks, reducing boilerplate code.
  3. Hibernate: Uses Hibernate for object relational mapping.
  4. Spring ORM: Integrates Hibernate into Spring framework, removing more boilerplate code.
  5. Spring Data JPA: Eliminates the need for manual queries, focusing solely on application logic.

Notes and Preparation

  • Focus on understanding project requirements to choose the appropriate Spring module(s).
  • Join provided WhatsApp group for further notes and video lectures.