SPRING FRAMEWORK –
Before going to start discussing the concept of spring framework, we need to understand what is meant by Framework?
So basically framework is a real or conceptual structure available to serve as a support or guide for the building of something into something useful.structure it consists of some set of rules, ideas,some readymade available things which you use in order to deal with problems or to decide what to do.
Spring is one of the lightweight and open source java frameworks used to develop java EE and web applications.
Released in June 2003 by Rod Johnson under the Apache 2.0 license, the Spring Framework is hosted by SourceForge.
Why should we go for Spring?
Java programs are complex and consist of many heavyweight components. Heavyweight means the components are dependent on the operating system of the machine for their working and properties.
Spring is considered as the most secure, low-cost and flexible framework. Spring improves coding efficiency and reduces application development time because it is lightweight and has a lot of support.
Spring removes complicated configuration tasks so that developers can focus on writing business logic. It does the configuration process automatically so developers can focus on the application.
How Spring Works?
Every web application commonly includes three layers:
- Presentation/view layer (UI) – This is the outermost layer which handles the presentation of content and interaction with the user simply it represents the designing part of the web application .
- Business logic layer – The middle layer that deals with the main logic of a program.
- Data access layer – The deep layer that deals with data retrieval from databases. Means in this layer our web application deals with database.
Each layer is dependent on the other for an application to work with. In other words, the presentation layer talks to the business logic layer, which talks to the data access layer.using spring frame the another class object. To understand this concept let us take one example.
Public void doWork()
Public void doWork()
Suppose we have 2 classes Raj and Priya. here , Raj is totally depend upon priya’s object to execute his doWork() method
In java,servlet,jsp we need to create an object of priya inside Raj by using new keyword. But if we are doing this here, in that case our s/w will be tightly coupled(means if we perform changes in the original class so that changes will also need to be performed in that where we have created the object of that original class ). So we make changes in Priya so we have to change in object also.
So, to avoid this we can take a help of spring framework, so in spring it has the capability to make the object of one class and inject it into the another class. Means of Raj is depend upon the object of Priya then spring can automatically create the object of Priya and inject it into the Raj. that’s why it is called as a dependency injection. Its just like injection through which we can inject medicine into the human body.
So, Spring uses the IOC(Inversion of Control) container, which can create an object of one class and inject it into the other class.
IOC means inversion of control so this object creation process can be controlled by the spring instead of programmer. And then spring framework can create an object of a class dynamically means at a runtime
Means in the above code, we can get the object of Priya inside p variable. But we have to tell to that to which object we need to store inside p so we can use xml file or annotation
So, this feature of injecting object of one class into the another class is called as “dependency injection”. So this is one of the features of spring i.e dependency injection. Apart from this Spring provides some modules(Spring JDBC,SPring ORM, Spring MVC(for UI layer)),services,API
Spring Modules –
Spring Core Modules –
Core and Beans –
These modules provides Dependency Injection and IOC features of spring framework.
It inherits the features from the bean module. It has the features of factory design pattern also. This module supports internationalization , event propagation,resource loading.
Expression Language –
It is an extension of the EL which is defined in JSP. It provides support to setting and getting property values of a bean,logical and arithmetic operators, named variables,method invocation, accessing collections, retrieval of objects by name etc.
AOP, Aspects and Instrumentation –
AOP provides the way to dynamically add the code or advice before or after the main logic without modifying the actual logic. It makes it easy to maintain code in the present and future as well. You can add/remove concerns without recompiling complete source code simply by changing configuration files
AOP compliments to Object Oriented Programming by providing another way of thinking about program structure
It is used to build messaging based applications. In this tool we have several annotations which is used to map the messages with methods
Data Access / Integration –
This group consists of JDBC, ORM, OXM, JMS and Transaction modules.By using these modules we basically interact with the database.
JDBC provides the data abstraction layers which accesses the data from the database easily and fastly
If we want to use Hibernate ORM in Spring then this Spring ORM is used. This is a integration tool and with the help of this tool we can integrate another ORM tool in our project.
OXM(Object Xml Mapping) it provides an abrasion ;layer which supports an object xml mapping
JMS(JAva Messaging Services) provides a services which produce and consume messages.
Web Module(MVC/Remoting) –
This web module basically consists of Web, Web-Servlet, Web-Portlet and Web-Struts. These modules provide support to create web applications.
Web provides web oriented integration features, like file uploading on server,creating REST API’s
Web-Servlet is used to create web servlets
Test module supports to do unit and integration testing.
SevenMentor Pvt Ltd
Call the Trainer and Book your free demo Class for now!!!
© Copyright 202! | Sevenmentor Pvt Ltd.