In this tutorial, we are going to discuss Spring introduction. Spring Framework is one of the most popular Java-based application frameworks. Spring framework is an open-source java platform, and it was created by “Rod Johnson” in 2003. Before going further, let’s discuss some essential points.
What is Enterprise?
An enterprise is a group of organizations running under a single label.
What is Enterprise Application?
Enterprise Application is a software application prepared for an enterprise to simplify its business processing. To prepare enterprise Applications, we have to provide the following three layers.
1. User Interface Layer
- The User Interface layer is the topmost layer in an enterprise application.
- It will provide a starting point for the users to interact with enterprise applications.
- It will provide an excellent environment to get data from users to submit data to server-side applications.
- The user interface will provide an excellent environment to send different request types from the client to the server like GET, POST, DELETE, PUT, etc.
- To prepare the User Interface layer, we must use a separate logic called “Presentation Logic”.
- In Enterprise Application development, to prepare presentation logic, we have to use the technologies like AWT, SWING, html, JSPs, Velocity, Free Marker, etc.
2. Business Processing Layer
- It is the heart of the enterprise application, and it can be used to define and execute all business rules and regulations required by the clients.
- In Enterprise Application development, to prepare the Business Processing layer, we have to use a separate logic called “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, and it will provide an excellent environment to interact with databases to perform persistence operations.
- To prepare this layer in enterprise applications, we must use a separate logic called “Persistence Logic”.
- To provide persistence logic, we have to use a set of technologies like JDBC, EJBs Entity Beans, Hibernate, etc.
To define the level or height of the enterprise applications, we have to use System Architecture. Mostly there are four types of System Architectures.
- 1-Tier Architecture.
- 2-Tier Architecture.
- 3-Tier Arch.
- n-Tier Arch.
- In 1-Tier Arch, we have to prepare and execute the complete enterprise application in a single machine.
- In 1-Tier Arch, we must provide all the enterprise application layers like presentation, business, and persistence layers in a single machine. There is no separation between all the layers. It will provide tightly coupled design in enterprise applications, and it is not suggestible.
- In the 1-Tier arch, we must execute the complete enterprise application in a single machine where single machine resources may not be sufficient to manage the entire enterprise application. It may affect the application’s performance.
- 1-Tier Arch is suggestible for Standalone Applications, not for enterprise Applications or distributed Applications.
- In 1-Tier Arch, Shareability and Reusability are significantly less; it may increase application length.
- In 1-Tier Arch, a multi-user environment has not existed; only a Single user environment has existed.
- In 2-Tier Arch, we have to distribute the complete enterprise application over two machines.
- In 2-Tier Arch, the Tier-1 machine can manage presentation logic and Business Logic, Tier-2 machine can manage Persistence Logic.
- In 2-Tier Arch, we can get loosely coupled design when compared with 1-Tier Arch because the Persistence layer is separated from the Presentation layer and Business Layer.
- In 2-Tier Arch, database components are shared with client applications. So that shareability and Reusability are increased.
- 2-Tier Arch will provide a multi-user environment to access the application.
If we want to use a 2-Tier arch for web applications, we have to use Tier-1 for a client. It has to manage the presentation layer, and Tier-2 is for the Server. It has to manage Business Layer and Persistence Layer.
- This architecture will propose to use three machines 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 a more loosely coupled design to design applications.
- 3-Tier Arch will provide a Multi-User environment. It will improve shareability and Reusability.
- 3-Tier arch will improve application Server component’s shareability and database components shareability.
If we increase the number of Tiers in applications, flexibility will increase, but maintenance costs will also increase. In enterprise applications, we have to increase the number of ties as per the purpose only. We must not increase the number of tiers unnecessarily.
There are two types of Enterprise Applications.
- Web applications [Web Related Distributed Applications]
- Distributed Applications [Remote based Distributed Applications].
Differences between Web Applications and Distributed Applications?
1. Web Application is a Client-Server Application, where the complete application logic is distributed over a Server machine.
Distributed Application is a client-server application, where the complete application logic is distributed over the Client machine and Server machine.
To prepare web applications, we will use a set of technologies called web technologies.
E.g. Servlets, JSP etc.
To prepare Distributed Applications, we will use a set of technologies called Distributed technologies.
E.g. Socket programming, RMI, CORBA, EJBs, Web Services etc.
3. The main intention of Web applications is to generate a dynamic response from the server.
The main intention of Distributed Applications is to establish Communication between local machines and remote machines to get Remote Services from Remote machine.
4. Web applications are executed by both web servers and application servers.
Only application servers execute distributed applications.
5. Web application is the collection of web components like servlets, JSP, etc., which are executed by web containers.
Distributed Application is the Collection of distributed components like EJBs, which EJB Container executes.
6. In web applications, the Client is fixed, that is, Browser.
In Distributed Applications, the Client is not fixed. It may be a regular java program with the main () method, a GUI Application, a Servlet program, a JSP program, etc.
To prepare web applications, SUN Microsystems has provided the following Modeled Architecture.
- Model-I Architecture
- Model-II Architecture
1. Model-I Architecture
- In Model-I Web Application Arch, we will use a JSP page as controller and Presentation part and a Java Bean component acting as Model Component.
- In Model-I web application Arch, a JSP page is acting as Controller to control 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 the 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 separation 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 application Arch, a JSP page is acting Controller, performing controller functionalities the existed JSP features are not sufficient. It is required to write java code inside JSP pages against JSP rules and regulations.
- 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, etc., as used as Model Components.
- In Model-II Arch, a servlet is acting as a 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 takes responsibility for taking all the requests from the Client, so that Model-II Arch is also called “Servlet Front Arch.”
Model-II Arch is the implantation of MVC Arch. Based on Model-II Arch, the web frameworks like Struts, JSF, etc., are designed.
Rules and regulations of MVC Architecture
- MVC is a design pattern, and it will define a standard template to prepare web applications.
- MVC will define the standard flow of execution to prepare web applications.
- In MVC-based web applications, we must use a Servlet as a controller and a set of JSP pages as a view part.
- In MVC-based web applications, we must provide a single Controller per application.
- In MVC-based web applications, the Controller component must take all the requests coming from clients, and the View part must take the responsibility to generate a response to the client.
- IN MVC-based web applications, both controller and view part is not responsible for interacting with a database, and they have to interact with the database through the Model component.
- In MVC-based web applications, the Controller can set data to the model component, not get data from the model component. The View part can get data from the model component, not set to the 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.
In general, from application to application, components like Controller, Servlet, and some generic Services like Internationalization, Security, Data Validations, etc., are very common. These common components may provide 70% implementation in the complete enterprise application. In the above context, if any third-party organization provides the common 70% implementation, developers may take responsibility for providing the remaining 30% of the implementation. In the above situation, some third-party organizations like Apache Software Foundations, Soft Tree, etc., have provided the common 70% of the implementation in their products called “Frameworks.”
- The framework is a pre-defined Software component that programmers can reuse, share and customize to simplify enterprise application development.
- The framework is a semi-implemented application. It will provide a very good environment to prepare enterprise applications as per the developer’s convenience.
- The framework is the Collection of Tools and APIs. It will provide a very good environment to prepare enterprise applications in a simplified manner.
In enterprise application development, Frameworks will provide the following advantages.
- Frameworks will define a 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, etc.
- Frameworks will reduce development time.
- Frameworks will reduce application development costs.
- Frameworks will increase productivity.
There are two types of Frameworks.
- Web Frameworks
- Application Frameworks
1. Web Frameworks
Web frameworks will provide an environment to design and execute only web applications.
E.g. Struts, JSF, Xwork2,
2. Application Frameworks
Application Frameworks will provide a very good environment to prepare all the types of applications like Standalone Applications, Web Applications, Distributed Applications.