UNIT – 5 WEB MVC FRAMEWORK
5.1 EXPLAIN WEB APPLICATION FRAMEWORK :
A web application framework is a software that helps in building web applications. It provides a
structure and tools to build web applications. Web frameworks use the Model-View-Controller (MVC)
architecture, which divides the application into separate layers to manage complexity efficiently.
5.1.1 IMPORTANCE OF MVC ARCHITECTURE :
The Model-View-Controller (MVC) architecture is important in web application development because
it clearly separates different parts of the application. It divides the application into three
interconnected parts : Model, View, and Controller. This separation improves code organization,
makes maintenance easier, and offers more flexibility for developers.
5.1.2 ADVANTAGES OF MVC ARCHITECTURE :
Some advantages of the MVC architecture include :
- Modularity : MVC makes the code modular, making it easier to manage and maintain different parts
of the application.
- Separation of Concerns : It separates the Model, View, and Controller, allowing developers to work
on different areas independently.
- Code Reusability : Its modular structure allows for code reuse, reducing duplication and improving
development efficiency.
- Ease of Testing : With clear separation, each part can be tested separately, making the application
easier to test overall.
5.2 DESCRIBE MVC ARCHITECTURE LAYERS :
In the MVC architecture, the Controller handles user interactions, updates the Model based on user
input, and decides which View to show to the user. The Model represents data and business logic also
handles data storage, retrieval and updates. The View is responsible for presenting data to the user and
takes in user input. The MVC architecture consists of three main layers :
5.2.1 MODEL LAYER :
The Model layer manages the application’s data and logic. It handles data storage, retrieval, and
manipulation. The Model is responsible for updating the View when data changes and notifies the
Controller of user actions.
5.2.2 VIEW LAYER :
Displays data to the user in a user-friendly way and forwards user actions to the Controller for
processing.
5.2.3 CONTROLLER LAYER :
The Controller layer manages user interactions and serves as an intermediary between the Model and
View. It processes user input, triggers the necessary actions in the Model, and updates the View as
needed.
5.3 ASPECT-ORIENTED PROGRAMMING (AOP) :
Aspect-oriented programming (AOP) is a programming approach that allows developers to organize
cross-cutting concerns which are features that affect multiple parts of an application, like logging,
security, and transaction management. AOP separate these concerns from the main business logic,
making the code easier to maintain and reuse.
5.3.1 DEPENDENCY INJECTION (DI) :
Dependency injection (DI) is a method used to achieve loose coupling between components in an
application. It allows the application define external dependencies required for a component and inject
them at runtime. DI improves code flexibility, testability, and makes maintenance easier.
5.3.2 PLAIN OLD JAVA OBJECT (POJO) :
Plain Old Java Object (POJO) is a simple Java classes that do not depend on any specific frameworks
or libraries. POJOs follow basic object-oriented principles without needing extra dependencies or
inheritance.
5.3.3 SPRING FRAMEWORK ARCHITECTURE :
The Spring Framework is a popular Java-based application framework for building enterprise-level
applications. It follows Inversion of Control (IoC) and Dependency Injection (DI) principles.
Explanation :
1. Core Container : This is the core part of the Spring Framework. It includes the Bean Factory and
Application Context. The Bean Factory is responsible for creating and managing objects (beans) in
the application. The Application Context provides more advanced features like dependency injection
and internationalization.
2. AOP (Aspect-Oriented Programming) : This module supports Aspect-Oriented Programming,
allowing developers to modularize cross-cutting concerns like logging, security, and transactions.
3. Data Access/Integration : This module offers tools for data access, including JDBC for databases,
ORM (like Hibernate) for object-relational mapping, and JMS for messaging.
4. Web : The Web module offers features like Web MVC for building web applications, WebSocket
for real-time communication, and other web development utilities.
5. Test : The Test module provides support for testing Spring applications, including unit testing and
integration testing.
The Spring Framework's modular architecture allows developers to choose the specific modules
needed for their projects, making it a flexible and powerful framework for building enterprise-level
applications.
The core features of the Spring Framework include :
1) Dependency Injection (DI) :
- Manages and injects dependencies of various components, promoting loose coupling.
2) Aspect-Oriented Programming (AOP) :
- Allows separation of cross-cutting concerns from the main logic.
3) Spring Container :
- Manages the creation and lifecycle of beans, enabling DI and loC.
4) Spring MVC :
- Provides a strong Model-View-Controller (MVC) framework for building web applications.
5.4 FEATURES IN SPRING BOOT :
Spring Boot is an extension of the Spring Framework that makes it easier to develop Spring-based
applications. Its features include:
1) Autoconfiguration : Spring Boot automatically configures various components based on the
dependencies in the classpath.
2) Embedded Server : Spring Boot includes an embedded web server (e.g., Tomcat, Jetty), so you can
run applications without needing a separate server.
3) Starter Dependencies : Spring Boot provides starter dependencies that simplify the process of
configuring and building applications with specific features (e.g., Spring Data, Spring Security).
4) Actuator : Spring Boot Actuator provides endpoints to monitor and manage the application in
production.
5.4.1 Comparison between Spring & Spring Boot :
Feature Spring Spring Boot
Configuration Complexity Requires manual configuration Offers autoconfiguration &
simplified setup
Embedded Server Requires manual configuration Includes an embedded server
(eg. Tomcat, Jetty) (Tomcat, Jetty) for quick
deployment
Dependency Management Requires manual management Offers starter dependencies for
of dependencies simplified dependency
management
Development Ease Slightly more complex Simplified development with
conventions & defaults
Monitoring & Management Requires additional setup Includes Spring Boot Actuator
for out-of-the-box management