Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Spring Introduction

The document outlines the structure and components of enterprise applications, emphasizing the three layers: User Interface, Business Processing, and Data Storage/Access. It differentiates between Web and Distributed applications, discusses various web application architectures, and highlights the importance of frameworks like Spring for simplifying application development. Additionally, it compares Spring with other frameworks like Struts and JSF, detailing their respective functionalities and advantages.

Uploaded by

Praveen
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Spring Introduction

The document outlines the structure and components of enterprise applications, emphasizing the three layers: User Interface, Business Processing, and Data Storage/Access. It differentiates between Web and Distributed applications, discusses various web application architectures, and highlights the importance of frameworks like Spring for simplifying application development. Additionally, it compares Spring with other frameworks like Struts and JSF, detailing their respective functionalities and advantages.

Uploaded by

Praveen
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 26

Class Notes: https://tinyurl.

com/SPRING6PM
Mobile No: 7386095600
Spring
—-----
1.Introduction
2.Core Module
3.JDBC Module
4.AOP Module
5.ORM Module
6.TRANSACTIONS Module
7.WEB MVC Module

Introduction
—------------
Enterprise: A group of organizations running under a single
label is called an Enterprise.

Enterprise Application: It is a software application which


simplifies the business processing inside the enterprises.

To prepare Enterprise applications we have to provide the


following three layers.

1.User Interface Layer


2.Business Processing layer
3.Data Storage/Access Layer

User Interface Layer:


—--------------------
1.User Interface Layer is providing an entry point for
all users to interact with the Enterprise applications.
2.User Interface Layer is providing a very good look and
feel to the customers in order to access the enterprise
applications.
3.User Interface is able to provide an environment to
perform client side data validations by defining Java
script functions.
4.To send different types of requests like GET, POST,
PUT, DELETE,....from client to the server we have to
use user Interface.
5.To prepare an User Interface Layer we will use a
separate logic called Presentation Logic.
6.In Enterprise applications, to prepare presentation
logic we will use a set of technologies like HTML, CSS,
BOOTSTRAP, JAVA SCRIPT, JQUERY, AJAX,.....

Business Processing Layer:


—-------------------------
1.It is the heart of enterprise applications.
2.It will provide a very good environment to define all
the clients required business rules and regulations.
3.To prepare the Business Processing layer we have to use
a separate logic called Business Logic.
4.To prepare Business logic in Enterprise applications we
have to use a set of technologies or components like
Business Objects, EJBs, Servlets,....

Data Storage And Access Layer:


—------------------------------
1.It is the bottom most layer in the Enterprise
applications.
2.The main intention of this layer is to interact with
the databases in order to perform the database
operations in enterprise applications.
3.To prepare the Data Storage and Access layer in
Enterprise applications we have to use a separate logic
called “Persistence Logic”.
4.To prepare Persistence Logic in enterprise applications
we have to use a set of technologies and tools like
JDBC, Hibernate, Ejbs Entity Beans, JPA, Data JPA,.....

There are two types of Enterprise Applications.

1.Web Applications
2.Distributed Applications

Q)What are the differences between Web Application and


Distributed Application?
—----------------------------------------------------------
---
Ans:
—---
1.Web application is a Client-server application, where
the complete application logic is distributed at Server
machine only.
Distributed application is a Client-Server application,
where the complete application logic is distributed
over the multiple machines that are client and Server
machines.

2.IN Web applications, Client is fixed, that is Browser.

In Distributed applications, Client is not fixed, it


may be a normal java program with main() method, a
servlet, a JSP page, a framework application like
Struts, JSF, Spring,.....

3.To prepare Web applications, we will use a set of


technologies called Web technologies.
EX: CGI, Servlets, JSPS, PHP, ASP.NET,....

To prepare Distributed applications we will use a set


of technologies called Distributed technologies.
EX: Socket Programming
RMI
CORBA
EJBs
Web Services

4.The main intention of the web applications is to


generate dynamic responses with a very good look and
feel.

The Main intention of the Distributed applications is


to establish communication between Local machine and
remote Machine and to consume the remote services
provided by the Remote Application.
5.Web applications are executed by both web servers and
application servers.

Distributed applications are executed by only


Application Servers.

6.Web application is the collection of Web components


like Servlets, JSPs,..., where to execute web
components we will use web containers.

Distributed application is the collection of


Distributed components like EJB components, where to
execute distributed components we will use the
distributed container like EJB Container.

Note: in Enterprise Applications we need both Web


Components and Distributed Components.

Enterprise Application=Web Application + Distributed


Application
To prepare web applications, we will use the following two
Architectures.

1.Model-I Web Application Architecture


2.Model-II Web Application Architecture

Model-I Web Application Architecture


—------------------------------------
Model-I Web Application Architecture is an outdated
Architecture to prepare web applications.

In Model-I Web Application Architecture, we will use a JSP


page / JSP Pages as a front controller and View part , a
Java bean component acting as Model.
In the Model-I Web application Architecture, a JSP page is
acting as a Front controller which is taking responsibility
to take all requests from Clients and processing those
requests, due to this reason Model-I Web Application
Architecture is called “JSP-Front” Architecture.

In Model-I Web application Architecture, a single JSP page


is acting as a controller which will control the complete
web application, so this architecture is also called “Page-
Centric Architecture”.

Drawbacks:
—---------
1.It is an outdated Architecture, it is providing limited
support for the web application development, it is not
utilized in the present web application’s development.
2.In This Architecture, no separation between Controller
and View components, it will provide tightly coupled
design in the web application development, it is not
suggestible.
3.In this Architecture, we will use a single JSP page as
controller, in web applications controllers must
perform a number of activities like recognition of the
modules, loading modules, preparing configurations for
each and every module and preparing a separate
processor for each and every module,...., to achieve
all these responsibilities the existing features of JSP
technology are not sufficient, where there is a
requirement to write Java code inside the JSP pages, it
is against to the JSP rules and regulations, due to
this reason this architecture is providing in stable
architecture for the web application development.

2. Model-II Web Application Architecture:


—----------------------------------------
Model-II Web Application Architecture is not an outdated
Architecture to prepare web applications, it is utilized
for the at present web applications.

In Model-II Web Application Architecture, we will use a


Servlet as a front controller , a set of JSP pages as View
part and the components like Java beans, EJs Session beans,
DAOs,... as Model.
In this architecture, a Servlet is acting as a Front
Controller which is taking all requests from clients and
processing all the requests, so this architecture is also
called a Servlet-Front Architecture.

In this Architecture, a Servlet is acting as a controller,


it controls the complete web application , so this
architecture is also called a Servlet-Centric Architecture.

This Architecture is following MVC[Model-View-Controller]


rules and regulations, so this architecture is also called
MVC Architecture.

The web applications Frameworks like Struts, JSF, XWork2,


Spring WEB MVC,... are designed on the top of Model-II Web
Application architecture that is MVC Architectures, so
these frameworks are called MVC based Frameworks.

MVC Rules and Regulations:


—-------------------------
MVC is a design pattern, it will provide a standard
template to the web application.

MVC design pattern will provide a standard fixed flow of


execution in the web applications.

If we want to prepare web applications on the basis of MVC


design pattern then we have to use the following rules and
regulations.
1.In MVC based web applications we must provide a servlet
as controller and a set of JSP pages as View part, we
must not interchange these components.
2.In MVC based web applications, only one front
controller must be provided.
3.In MVC based web applications, every request must be
provided to the Controller only and every response must
be provided by the View part only.
4.In MVC based web applications, Controllers must
interact with the Model components to set the data in
order to execute business logic and the View part will
interact with the Model component to get the data.
5.In MVC based web applications, Controllers must not
interact with the database directly, it has to interact
with the database through the model components only.
6.IN MVC Based web applications, we will provide more JSP
pages as per the requirement, but all the JSp pages
must be provided as Java code less JSP pages.
7.In MVC based web applications, we will provide more
than one JSp page as part of View, but we must not
provide Page-To-Page communication, here we must
provide Page-Controller-Page communication.

Q)To prepare and execute web applications we have already


1.Server side technologies like Servlets, JSPs,...
2.Servers like Tomcat, Weblogic, Wildfly, Glassfish,....
3.IDEs like Eclipse, Intellij Idea,....
4.Design models like Model-I Arch , MVC,....
5.Real time tools like MAVEN, GRADLE, Log4j,...
—----
—----
Still what is the requirement to use Frameworks to develop
the applications?
—----------------------------------------------------------
----
Ans:
—----
In general, in all the applications the components like
Controllers, Beans,.. And the Services like Data
Validations, Security, I18N, Logging,...... are common,
where these common components and common services may take
nearly 70% of the actual application implementation, here
only the 30% of the application implementation is varied
which is specific to the clients.

In the above context, if we provide the complete enterprise


application implementation 100% explicitly then it may take
a lot of development time, it will increase the overall
application development cost and it will reduce the
application productivity.

To overcome all the above problems we need an alternative


where we have to get the common 70% of the implementation
as ready made implementation in the form of a product,
where the developers will put focus on only 30% of the
application implementation which is client specific.

In the above context, some third party organizations have


provided their own products to provide the common 70% of
the application implementation called “Frameworks”.
Framework:
1.Framework is a pre-fabricated software components that
programmers can reuse, extend, share and customize in
order to simplify and accelerate the application
development.
2.Framework is a semi implemented application, it will
provide a very good environment to prepare the
enterprise applications as per the developers comfort.
3.Framework is the collection of tools and APIs to
simplify application development.

In Enterprise application Development, Frameworks will


provide the following advantages.

1.Simplify the application Development.


2.Reduces the application development time.
3.Reduce the Application Development Cost.
4.Increases the application Productivity
5.Provides generic services like Validations, I18N,
Security, Transactions,....
6.Provides a set of tools like MAVEN, GRADLE, LOG4J,...
7.Provides a standard template to prepare the
applications.
8.Provides a standard flow of execution to the
Applications.

There are two types of Frameworks.

1.Web Frameworks
2.Application Frameworks

Q) What are the differences between Web Frameworks and


Application Frameworks?
—----------------------------------------------------------
--
Ans:
—---
Web Frameworks are able to provide a very good environment
to prepare and execute the web applications only.

EX: Struts, JSF, XWORK2,...

Application Frameworks are able to provide a very good


environment to prepare the applications like
1.Standalone Applications
2.Web Applications
3.Distributed applications
4.Database Related Applications
5.Message Oriented Applications
—-----
—-----
EX: Spring and Spring Boot

Q) What are the differences between Struts, JSF and Spring


Framework?
—----------------------------------------------------------
----
Ans:
—---
1.Struts and JSF are the web Frameworks, they are able to
provide an environment to prepare only web applications
or only the web layer in the enterprise applications.

Spring Framework is an Application Framework, It is


able to provide an environment for all the types of
applications like Standalone applications, web
applications, distributed applications, database
related applications,...

2.Struts Framework is a controller layered framework,


which focuses mainly on the controller layer.
JSF Framework is a View Layered Framework, it focuses
mainly on the View layer in the Enterprise
applications.

Spring Framework is able to provide a very good


environment for all the layers of the Enterprise
applications like View layer, Controller Layer,
Model,.....

3.Struts and JSF are not modularized frameworks, to


prepare any simple application the complete Framework
has to be loaded.

Spring Framework is a modularized Framework, to prepare


any simple application it is required to load the
respective module only, it is not required to load all
the modules of the Spring Framework.

4.Struts and JSF are heavy weight Frameworks

Spring Framework is a Lightweight framework.

5.Struts and JSF are more API dependent, so it is very


difficult to perform Debugging and Testing.

SPring Framework is less API dependent, so it is very


simple to perform Debugging and Testing.

6.Struts and JSF are not having POJO classes, they are
having some other bean components like Form Beans,
Backing Beans,...they are very difficult to prepare and
to manage.
Spring Framework has the POJO classes, they are very
simple to prepare and manage in the applications.

Note: Any Java bean class which does not extend or


implement predefined libraries is called a POJO class.

POJO: Plain Old Java Object.

7.Struts and JSF are using only MVC and its co-related
design patterns.

Spring Framework used more design patterns along with


MVC and its co-related design patterns

8.Struts and JSF are not providing any integration layer


to integrate the other applications like EJBs
applications, Ajax Applications,....

Spring Framework has provided an integration layer to


integrate the other applications like EJBs
applications, Web Applications, ….

JDBC: To integrate JDBC code.


ORM : To integrate ORM implemented applications like
Hibernate, JPA,...
WEB : To Integrate Struts, JSF,... MVC based
applications
AOP : To integrate all the middleware services like
JAAS,
Transactions, Validations,...

9.Struts and JSF do not have AOP programming.


Spring Framework supports AOP programming.

10. Struts and JSF do not have Transactions support.

Spring Framework has provided very good transaction


support in the enterprise applications.

11. Struts and JSF do not have the ORM applications


integration.

Spring Framework has an integration layer to integrate


ORM applications.

Spring History:
—----------------
Home : Interface1
Author : Rod Jahnson.
Objective : To simplify and Accelerate enterprise
application development.
Initial Versions : 1.x
Latest Version : 5.x, 6.x
Type : Application Framework.
Freeware/Licensed : Freeware and Open source.
Website : www.spring.io
Designed On : J2SE, JDBC API, Servlets API, JSPs
API,...
Spring Modules:
—---------------
Spring 1.x :

Spring 2.x:
Spring 3.x

Spring 4.x:
Spring 5.x

Overview of Spring Modules:


—---------------------------
Core Module:
This module will provide the basic elements or features of
the Spring Framework like Beans and its lifecycle,
Containers and their functionalities, Dependency
Injections, I18N, Validations, Event Handling…

JDBC Module:
If we prepare JDBC applications by using plain JDBC we have
to use the following steps.

1.Load and Register Driver:


Class.forName(“com.mysql.cj.jdbcDriver”);

2.Establish Connection between java application and


Database:
Connection con = DrierManager.getConnection(
“jdbc:mysql://localhost:3306/durgadb”,
“root”,
“root”
);

3.Create Statement:
Statement st = con.createStatement();

4.Write and Execute SQl Queries:


ResultSet rs = st.executeQuery(“select * from emp1”);

5.Close the connection:


con.close();

In the above JDBC steps, steps 1,2,3 and 5 are common in


all the JDBC applications, here the common steps are called
Boilerplate code; it is unnecessary in each and every JDBC
application.

If we use Spring Framework to perform the database


operations, where Spring JDBC module is able to abstract
the above boilerplate code and it provides an option to the
developers to provide only the “Write and execute sql
queries” option.

AOP Module:
In general, if we prepare applications by using Object
orientation then we have to provide both business logic and
the services logic in the combined manner, it will provide
tightly coupled design, it will reduce shareability and
reusability.

In the above context, SPring AOP Module is able to improve


shareability and Reusability by providing loosely coupled
design.

Spring AOP module is able to separate all the Services from


business logic, declared as aspects and inject these
aspects into the application business logic at runtime.
ORM Module:
ORM: Object Relational Mapping
EX: Hibernate
Its purpose is to perform the Database operations by
providing mapping between the elements from Objects
Orientation Data model and the Relational Data model
through an XML file or through annotations.

Class —------------> Table


Object —-----------> Record
ID Property—-------> PK Column
Property —---------> COlumn

To prepare applications by using Plain JDBC we need query


language knowledge, where we have to write SQL queries, but
in ORM implementation tools like Hibernate we are able to
perform Database operations without using SQL queries, just
by accessing java methods.

To prepare Applications by using Hibernate we have to use


the following steps.

1. Create a Configuration class object.

Configuration cfg = new Configuration();


cfg.configure(“hibernate.cfg.xml”);

It is able to store all the Hibernate configuration details


which we provided in the hibernate.cfg.xml file like
Database details, Driver class name, driver URL, database
user name, database password,....

2. Create SessionFactory object:

SessionFactory sf = cfg.buildSessionFactory();

It will collect the hibernate configuration details from


the COnfiguration objects and establish the connection
between Java application and the Database, create Statement
objects,....

3. Create Session Object:

Session session = sf.openSession();

It provides predefined methods to perform the Database


operations.

4. Perform the Database operations:


a.If we perform the database operations like select then
it is not required to perform Commit or roll back
operations, so it is not required to use the
Transaction object, where the Transaction object is
able to provide commit and rollback operations.

Employee emp = (Employee)session.get(Employee.class,


111);

b.If we perform the database operations like insert,


update and delete then it is required to perform the
operations like commit and rollback , so we need the
Transaction object.

Transaction tx = session.beginTransaction();
Employee emp = new Employee(111, “AAA”, 5000, “Hyd”);
session.save(emp);
Or
session.update(emp);
Or
session.delete(emp);

tx.commit(); or tx.rollback();

5. Close the resources:

sf.close();

In the above Hibernate applications the steps 1,2,3 and 5


are common in all the Hibernate applications, so these
steps are called Boilerplate code, it is not suggestible in
the Enterprise applications.

In the above context, Spring ORM module has provided a


solution by abstracting the above boilerplate code in the
form of HibernateTemplate class and it provides a set of
methods to perform the Database operations directly.

Messaging Module:
In Enterprise applications, we may get and send a number of
messages through the mobile messages or Main messages,.....
As per the requirement.

EX: IN Food Delivery Applications we need the Food Item


status as messages continuously from the restaurant and
from the Delivery Partner.

EX: In Transportation applications like Uber customers have


to get continuous messages from the User application.

In the above context, to provide messaging services a


number of tools exist like Active MQ, RabbitMQ and KAFKA.

Spring has provided a separate module in the form of Spring


messaging in order to integrate all the messaging tools
like Active MQ, RabbitMQ, Kafka,...

Spring WEB Module:


The main purpose of the Spring WEB Module is to integrate
the WEB MVC frameworks applications like Struts, JSF,....

Spring WEB MVC:


This module can be used to prepare MVC based web
applications directly. Spring Framework has its own MVC
framework in the form of Spring WEB MVC module.

You might also like