0% found this document useful (0 votes)
20 views

Spring Framework

detail about java spring framework and it workings in detail

Uploaded by

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

Spring Framework

detail about java spring framework and it workings in detail

Uploaded by

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

Spring framework is an open source Java platform that provides

comprehensive infrastructure support for developing robust Java applications


very easily and very rapidly. Spring framework was initially written by Rod
Johnson and was first released under the Apache 2.0 license in June 2003.
Spring is a lightweight framework. It can be thought of as a framework of
frameworks because it provides support to various frameworks such
as Struts, Hibernate, Tapestry, EJB, JSF, etc.

We can develop stand alone and enterprise application using Spring.


In 2003-Initial release
In 2004- Production release (1.0 version)

Advantages:
1. Modular and lightweight: allowing developers to use only the components
they need, making applications more lightweight and easier to maintain.

2. Flexible Configuration: supports multiple configuration options, including


XML based, Java based and annotations based configurations

3. Dependency Injection(DI): simplifies management of component


dependencies, making code more testable and adaptable to changes.

4. Aspect Oriented Programming(AOP): allowing developers to separate cross


cutting concerns like logging, security, and transactions from the core
application logic.

5. Simplified Database Access

6. Testing Support

7. Security

8. Integration Capabilities: easily integrate with various technologies and


frameworks, such as angular, react, messaging system(JMS), web
Services(SOAP and Rest) and other third party libraries and APIs.
9. Scalability: Spring applications can be designed for scalability and can
easily integrate with cloud native technologies and microservices
architecture.

10. Open Source: Free to use.

These are some major advantages of Spring.

Spring Container: This is core component of, ex:heart of spring.


Without spring container any spring application won’t work.
It is same like JVM.
Responsibilities:
1. Manage bean Object:(same as Java class, having private get and
set methods)
2. Manage bean life cycle.
3. Dependency Injection(DI)
4. Supports AOP.
5. Transaction Management.
6. I18N (Internationalisation support)

Types of Spring Container: To run all responsibilities(like JVM)


1. Beanfactory(Old Technique)
2. Application Context(Most recent technique in now a days)

POJO class: (Plain Old Java Object Class): A Simple java class with fields and
getters/setters method, used for data representation without framework
dependencies.
JavaBean class: A Serializable class, with no argument constructor, often used
to encapsulate data.
For Ex:
class Student
{
private String name;
private int rollno;
//getter & setter methods
}

Configurations file:- Instructions provide to Spring Conatainer,Which class


object should be created.
How we provide configurations:
 xml file
 java file
 annotation file

According to configurations Spring Container will read respected POJO class and
create and access of object of class.

Example:
Steps:1
1. Create new java project in eclipse.(File->New->project->java project)
2. Give name a SpringProgram1
3. Untick create-module info java file
4. Click on next
5. Click finish
6. Click on src->new->class
7. Give name as student and enter package name as in.mitwpu.beans

Why we give package names in reverse order


Ex: organisation name:MITWPU
Domain name: www.mitwpu.edu.in
Client Name: ICICI bank
Project Name: Loan
 Home Loan
 Car loan
 Education loan department

To give project name we use following method


in.mitwpu.icici.loan.homeloan;
8. To generate getter and setter method, right click->source->generate getter
and setter methods

Steps:2:- Create configuration file.


1. Right click on src->create new package->enter name as
in.mitwpu.resources
2. Right click on in.mitwpu.resources->new->file-> enter name as
applicationContext.xml
3. Open chrome and type spring configuration file xml schema

4. Click on first link


5. Copy xml part and paste in our project
6. Write bean tag in xml as follows
<bean class="in.mitwpu.Student" id="stdId">

</bean>
Spring Container will create one Object of Student class and name is
stdId
After creation of object, properties/variables of class will occupy
memory.

7. To set values to properties/variables write following code

<bean class="in.mitwpu.beans.Student" id="stdId">


<property name="name" value="Abhijeet"/>
<property name="rollno" value="101"/>
<property name="email" value="[email protected]"/>
</bean>
8. This means that, we are instructing Spring Container to set these values
to Student class Object.
9. Next create Main class, click on src->new->class->enter name as
Main and give package name as in.mitwpu.Main

10. Insert main method and JAR files for applicationContext


1.spring-beans-version.jar
//2.spring-core-version.jar
//3.spring-context-version.jar
//4.commons-logging-version.jar
//5.spring-expressions.jar
These JAR files we need to add in our project.

11. Open google and type download spring-beans jar


12. Click on Maven Repository

13. Click on latest version 6.0.12

14.Click on jar tab, file will download


15. repeat the same procedure for remaining jar files
16.Right click on Project Name and build path->configure build path-
>and add all JAR files to project.

17. Write following code


public class Main
{
String config_loc="/in/mitwpu/resources/applicationContext.xml";
ApplicationContext context= new ClassPathXmlApplicationContext(config_loc);
}

You might also like