Friday, October 21, 2022

Spring Framework - Introduction

1. Enterprise Application
Enterprise:
  • It is a business organization, it is a group of organizations running under single label.
Enterprise Application: 
  • It is a software application prepared for an enterprise in order to simplify their business processing.
  • To prepare Enterprise Applications, we have to provide the following three layers.
2. Enterprise Application Layers

1. User Interface Layer:

  • This layer is the topmost layer in enterprise application
  • It will provide a starting point for the users in order to interact with enterprise applications.
  • It will provide a very good environment to get data from users to submit data to server-side applications.
  • It will provide a very good environment to perform client-side data validations with javascript functions.
  • The user interface will provide a very good environment to send different request types from client o server like GET, POST, HEAD , ......
  • To prepare the User Interface layer, we have to use a separate logic called as "Presentation Logic".
  • In Enterprise Application development, to prepare presentation logic we have to use the technologies like AWT, SWING, html, JSPs, Velocity, Free Marker, and OGNL.
2. Business Processing Layer:

  • It is the heart of the enterprise application, it can be used to define and execute all business rules and regulations which are required by the clients actually.
  • In Enterprise Application development, to prepare
  • Business Processing layer we have to use a separate logic called as "Business Logic".
  • To provide Business Logic we have to use the technologies like Servlets, EJBs, DAOs, .....
3. Data Storage And Access Layer:

  • This layer is the bottom-most layer in enterprise applications, it will provide a very good environment to interact with databases in order to perform persistence operations.
  • 2To prepare this layer in enterprise applications we have to use a separate logic called as "Persistence Logic".
  • To provide persistence logic we have to use a set of technologies like JDBC, EJBs-Entity Beans and Hibernate.

3. System Architectures
System Arch :

  • To define the level or height of the enterprise applications we have to use System Arch. 
  • EX:

    • 1-Tier Arch. 
    • 2-Tier Arch. 
    • 3-Tier Arch.
    • n-Tier Arch.
1-Tier Arch

  • In 1-Tier Arch, we have to prepare and execute the complete enterprise application witin a single machine.
  • In 1-Tier Arch, all the enterprise application layers like presentation Layer, Business Layer, and Persistence layer must be provided in a single machine, no separation between all the layers, it will provide tightly coupled design in enterprise applications, it is not suggestible.
  • In 1-Tier arch, the complete enterprise application must be executed in a single machine, where single machine resources may not be sufficient to manage the complete enterprise application, it may affect the application performance.
  • 1-Tier Arch is suggestible for Standalone Applications, not for enterprise Applications or distributed Applications.
  • in 1-Tier Arch, Sharability and Reusability are very less , it may increase application length.
  • In 1-Tier Arch, multi user environment is not existed, only Single user environment is existed.

2-Tier Arch:

  • IN 2-Tier Arch, we have to distribute the complete enterprise application over two machines.
  • In 2-Tier Arch, Tier-1 machine is able to manage presentation logic and Business Logic, Tier-2 machine is able to manage Persistence Logic.
  • In 2-Tier Arch, we are able to get loosely coupled design when compared with 1-Tier Arch, because, Persistence layer is separated from the Presentation layer and Business Layer.
  • In 2-Tier Arch, database components are shared to client applications, so that, sharability and Reusability are increased.
  • 2-Tier Arch will provide multi-user environment to access applications.
  • Note: If want to use 2-Tier arch for web applications then we have use Tier-1 for client , it has to manage the presentation layer and Tier-2 for the Server, it has to manage Business Layer and Persistence Layer.


3. 3-Tier Arch:

  • This arch will propose to use three machines in order to execute the complete enterprise application.
  • In 3-Tier Arch, we will provide Presentation Layer at Tier-1 Machine, Business Layer at Tier-2 machine and Persistence layer at Tier-3 machine.
  • 3-Tier arch will provide more more loosely coupled design to design applications. - -> 3-Tier Arch will provide Multi User environment, it will improve sharability and Reusability.
  • 3-Tier arch will improve application Server components sharability and database components sharability.
  • Note: If we increase no of Tiers in applications then flexibility will be increased, but, maintenance cost will be increased. In enterprise applications we have to increase no ties as per the purpose only, we must not increase no of tiers unnecessarily.

4. Types of Enterprise Applications
There are two types of Enterprise Applications.
  1. web applications[Web Related Distributed Appl] 
  2. Distributed Applications[Remote based Distributed Appl].
What are the differences between Web Applications and Distributed Applications?

  • Web Application is a Client-Server Application, where the complete application logic is distributed over Server machine.
  • Distributed Application is a client-server Application, where the complete application logic is distributed over Client machine and Server machine.

  • To prepare web applications, we will use a set of technologies called as web technologies.
  • EX: 
    • Servlets, 
    • JSPS,

  • To prepare Distributed Applications, we will use a set of technologies called as Distributed technologies.
  • EX: 
    • Socket programming RMI
    • CORBA
    • EJBs
    • Web Services

  • The main intention of Web applications is to generate a dynamic responses from servers.
  • The main intention of Distributed Applications is to establish Communication between local machines and remote machines in order to get Remote Services from Remote machines.
  • Web applications are executed by both web servers and application servers.
  • Distributed applications are executed by only application servers.
  • Web application is the collection of web components like servlets, jsps,which are executed by web containers.
  • Distributed Application is the Collection of distributed components like EJBs, which are executed by EJB Container.
  • In web applications, the Client is fixed, that is, Browser.
  • In Distributed Applications, the Client is not fixed, it may be a normal java program with the main() method, it may be a GUI Application, it may be a Servlet program, or it may be a JSP program.

5. Modeled Arch
To prepare web applications, SUN Microsystems has provided the following Modeled Arch.
  1. Model-I Arch. 
  2. Model-II Arch.

1. Model-I Arch

  • In Model-I Web Application Arch, we will use a JSP page as controller as well as Presentation part and a Java Bean component is acting as Model Component.
  • In Model-I web application Arch, a JSP page is acting as Controller to controll the complete web application, so that, Model-I Web application Arch is also called as "Page-Centric Arch".
  • In Model-I web application Arch, a JSP page is taking responsibility to take requests from client, so that, Model-I web application Arch is also called as "JSP Front".
  • IN Model-I web application Arch, we will use JSP pages as Controller and for presentation, there is no clear cut seperation between Controller logic and presentation logic, it will provide tightly coupled design in web applications, it is not suggestible in web applications.
  • In Model-I web applicatio Arch., a JSP page is acting controller, to perform controller functionalities the existed JSP features are not sufficient, where it is required to write java code inside JSP pages, it is against to JSP rules and regulations.
  • In Model-I web applicatio Arch., a JSP page is acting controller, to perform controller functionalities the existed JSP features are not sufficient, where it is required to write java code inside JSP pages, it is against to JSP rules and regulations.

2. Model-II Arch

  • In Model-II web application Arch, we will use a Servlet as controller, a set of JSP pages as View part and Java bean, DAO, JDBC,... as used as Model Components.
  • In Model-II Arch, a servlet is acting as controller to control the complete web applications, so that, Model-II web Arch is called as "Servlet-Centric Arch".
  • In Model-II Arch, a servlet is taking responsibility to take all the requests from Client , so that, Model-II Arch is also be called as "Servlet Front Arch".
  • Note: Model-II Arch is an implantation of MVC Arch, on the basis of Model-II Arch only the web frameworks like Struts, JSF,... are designed. 

6. MVC
Rules and regulations of MVC Arch:

  • MVC is a design pattern, it will define a standard template to prepare web applications. 2. MVC will define standard flow of execution to prepare web applications.
  • In MVC based web applications, we must use a Servlet as controller and a set of JSP pages as view part.
  • In MVC based web applications, we must provide single controller per application.
  • In MVC based web applications, Controller component must take all the requests which are coming from clients and View part must take the responsibility to generate response to client.
  • IN MVC based web applications, both controller and view part are not responsibile to interact with database, they have to interact with database through Model component.
  • In MVC based web applications, Controller is able to set data to model component, not to get data from model component and View part is able to get data from model component , not to set data to Model component.
  • IN MVC based web applications, we can provide any no of pages as view part, but we must provide all the pages as Java code less.
  • IN MVC based web applications, we can provide no of pages as view part, where we must not provide page-to-page communication directly, where we have to provide page- controller-page communication.

Notes 

  • In general, from application to application, some components like ControllerServlet and some generic Services like Internationalization, Security, Data Validations,.... are very mush common, these common components may provide 70% implementation in the complete enterprise application.
  • In the above context, If any third party organization is providing the common 70% implementation then developers may take responsibility to provide the remaining 30% of the implementation.
  • In the above situation, some third party organizations like Apache Software Foundations, Soft Tree, .... has provided the common 70% of the implementation in the form of their own products called as "Frameworks".
  • Framework is a pre fabricated Software components that programmer can reuse, share and customize inorder to simplify enterprise application development.
  • Framework is a semi implemented application, it will provide very good environment to prepare enterprise applications as per developers convenience.
  • Framework is the Collection of Tools and APIs, it will provide very good environment to prepare enterprise applications in simplified manner.


In enterprise application development, Frameworks wil provide the folowing advantages

  • Frameworks will define standard template to design applications.
  • Frameworks will define a fixed flow of execution between the components. 
  • Frameworks provide parallel development and modularization.
  • Frameworks will provide all the commonly used generic services like I18N, Security, Exception handling, Data validations,....
  • Frameworks will reduce development time.
  • Framewords will reduce application development cost.
  • Frameworks will increase productivity.


7. Types of Frameworks
There are two types of Frameworks 
  1.  Web Frameworks
  2.  Application Frameworks
    
1. Web Frameworks
  • Web frameworks will provide environment to design and execute only web applications. EX: Struts, JSF, Xwork2

2. Application Frameworks
  • Application Frameworks will provide very good environment to prepare all the types of applications like Standalone Applications, Web Applications, Distributed Applications,.....
  • EX: 
    • Spring
8. Differences between Spring and Struts, JSF

  • Struts and JSF are web frameworks,which we will provid every good env ironment to prepare and execute web applications only.
  • Spring Framework is an application Framework, it will provide very good environment to prepare and execute all the types of applications like standalone applications, web applications, distributed applications......
  • Struts and JSF are designed on the basis of only MVC design pattern.
  • In Spring , only WEB Module is designed on the basis of MVC, SPriong is using no of other design patterns like IOC[Dependency Injection], Locater design patterns, Creational Design Patterns, Decorator Design pattern,.....
  • Struts is controller layered framework, it has very good focus on controller layer in MVC.
  • JSF is is view layered Framework, it has very good focus on View layer in MVC. Spring Framework has provided very good support for all Controller Layer, Model Layer and View Layer.
  • In Enterprise Application Development, Struts and JSF are used to prepare mainly Presentation layer.
  • In Enterprise Application Development, Spring Framework will cover all the layers like Presentation Layer, Business Layer, Persistence Layer.
  • Struts and JSF are provide support for the basic services like I18N, Validations, Exception Handling,..., but, Struts and JSF are not providing support for the middleware services like JAAS, JNDI, JTA, Java Mail, JMS,......
  • Spring Framework is providing very good support for all basic services like I18N, Validations, Exception Handling ... and the Middleware services like JAAS, JNDI, JTA, Java Mail, JMS, JCA......
  • Struts and JSF are not modularized Frameworks, to prepare any application in Struts and JSF we have to load all the jar files irrespective of their utilization.
  • Spring framework is modularized framework, to prepare applications in spring framework we will load only the module respective jar files, not required to load other modules respective jar files unnecessarily.
  • Struts and JSF are more API dependent; they are not having POJO/POJI kind of implementations.
  • Spring is less API dependent, it has POJO/POJI kind of implementations.
  • Due to the above reasons, debugging and testing are difficult in Struts and JSf. Testing and Debugging are very simple in Spring framework.
  • Struts and JSF are heavy weight Frameworks. Spring is light weight Framework.
  • Struts and JSF are not providing any predefined support to integrate the other applications like JDBC, EJBS, Hibernate, JPA, RMI,....
  • Spring has provided very good predefined support to integrate the other applications like JDBC, EJBS, Hibernate, JPA, RMI,....
  • Struts and JSF are allowing the basic view related technologies like Html, JSp, ..... to prepare view part.
  • Spring Framework is allowing the most advanced view related tech like Velocity, Free marker,... along with basic view related tech in order to prepare view part.
  • Struts and JSF are not having Aspect Oriented Programming to prepare applications. Spring has provided very good Aspect Oriented Programming to prepare Applications.
9. Spring History

  • Home: Interface1 
  • Author: Mr. Rod Janson
  • Objective: To simplify and Accelerate the complete Enterprise Applications. 
  • Type: Open Source Software.
  • Type of Framework: Application Framework. 
  • Initial Version: Spring1.0[Oct, 2004]
  • Used Version: Spring3.x[Dec, 2014] 
  • Latest Version: Spring4.3.8[April, 2017] 
  • Website: http://spring.io
  • Designed on: Java[JAVA SE API, Servlets API] 
  • Compatibility:Supported by All IDEs and all Servers
  • Designi Tool: STS[Spring tool Suit][Designed on the top of Eclipse]

10. Spring Modules

Spring1.x version
Spring2.x Version
Spring3.x Version
Spring4.x /5.x Version

Core Module:

  • It is fundamental module in Spring Framework; it has provided basic foundation for all other modules of spring framework.
  • This module can be used to prepare Standalone Applications directly.
  • This module is able to provide the features like IOC Containers, Beans, Dependency Injection.....


AOP Module[Aspect Oriented Progr]

  • IN general, if we prepare enterprise applications by using only Object Orientation then we have to provide both business logic and Services like Transactions, JMS, JAAS,.... in a combined manner, it will provide tightly coupled design, it will provide less sharability and less reusability.
  • In the above context, to improve sharability and Reusability we have to provide loosely coupled design, to get the loosely coupled design we have to apply Aspect Oriented Programming.
  • In Aspect Oriented Programming, we will declare each and every service as an aspect and we will inject these aspects in Business Logic at runtime.


JDBC/DAO Modules

  • The main intention of this module is to interact with database from Spring application inorder to perform database operations with JDBC Persistance mechanism.
  • JDBC/DAO modules are able to abstract common JDBC implementation inorder to simplify Database interaction from spring applications by providing template classes.

  • EX: In JDBC, if we want to interact with the database then we have to use the following steps.
  • Steps 

    1. Load And Register Driver
    2. Establish a Connection between Java appl and DB.
    3. Create Statement/PreparedStatement/ CallableStatement as per the requirement.
    4. Write and Execute SQL Queries
    5. Close the Connection
  • Example
    Class.forName("oracle.jdbc.OracleDriver");
    Connction con=DriverManager.getConnection("jdbc: oracle:thin:
    @localhost:1521:xe", "system", "cloud");
    Statement st=con.createStatement();
    ResultSet rs=st.executeQuery("select * from emp1");
    con.close();
  • Spring DAO and JDBC modules are having their own Exception Classes hierarchy to expose the exception details.
  • Spring DAO/JDBC modules are converting the JDBC generates checked exceptions to Spring defined Unchecked Exceptions by using Exceptions Re-Throwing Mechanism.

  • Example:
  • try{
    ---Exception-1 ----JDBC Checked Exception
    }
    catch(Exception_Name e){
    ----Exception-2---Spring Unchecked Exception 
    }
ORM Module[Object-Relational Mapping]:

  • ORM is the mapping between a table, properties or columns and primary key column with the respective bean component provided Bean class name, ID property, normal properties

  • ORM has define a set of rules and regulations to provide mapping between Object Oriented Data Model and Relational Data Model in order to achieve data persistency.
    • EX: Hibernate, JPA, Toplink,....

  • To prepare Hibernate Application then we have to use the following instructions. 

  • Steps

  • 1.Create Configuration class object.
    2.Create SessionFactory class object
    3.Create Session object
    4.Perform Persistance operations
    5.Close SessionFactory and Configuration
  • Example 
  • Configuration cfg=new Configuration(); cfg.configure();
    SessionFactory sf=cfg.buildSessionFactory();
    Session s=sf.openSession
    Object obj=s.load("com.cloud.Employee.class", 111);
    sf.close(); 
    cfg.close();

  • In the above Hibernate Application steps, Create Configuration class object, Creation SessionFactory object , create Session object and close SessionFactory and Configuration steps are very common in all hibernate applications, in this case, Spring ORM module is able to abstract all the common instructions in order to simplify Data persistence in enterprise applications.
  • Spring ORM module has provided its own Exceptions hierarchy to expose behalf of the under lying Persistence mechanism like Hibernate, JPA,.... provided checked exceptions.


JAVA EE/Context/Remoting
  • The main intention of this module is to integrate Spring applications with distributed tech applications like EJBs, RMI,.... it is able to get middleware services like JNDI, JTA, JAAS,.... from J2EE .

WEB/WEB-MVC Modules

  • WEB Module has provided very good environment to integrate other MVC based framework applications like Struts, JSF, XWork2,.....
  • WEB-MVC is an MVC implementation provided by Spring framework directly inorder to prepare web applications.

Test Modules:

  • Spring Framework has provided its own testing environment to test the enterprise applications by the developers[Unit Testing] in their own way in the form of Test module.
  • Note: Spring framework has provided Test module right from its Spring3.x version.

Instrumentation Modules:
  • Spring Framework has provided Instrumentation API to perform manipulations over the actions which are generated from the .class files with out having modifications over the source code.
Messaging Modules:

  • Spring Framework has provided Messaging module along with its Spring4.x version to provide Messaging Services that JMS is providing previously as part of J2EE.
  • Note: When we perform any transactions in the bank application , we are able to receive
  • mobile updations, in this context, if our mobile device is not ready to receive messages
  • WEB Module has provided very good environment to integrate other MVC-based framework applications like Struts, JSF, and XWork2.
  • We have to keep the respective message in Messaging Container or JMS Server to send the respective message when the target machine/device is ready.

You may also like

Kubernetes Microservices
Python AI/ML
Spring Framework Spring Boot
Core Java Java Coding Question
Maven AWS