What Is Spring Framework | Spring Framework Architecture | Edureka
Spring Framework (10 Blogs) Become a Certified Professional

What Is Spring Framework? – Path To Efficient Development

Last updated on Mar 04,2022 39.7K Views

Swatee Chand
Sr Research Analyst at Edureka. A techno freak who likes to explore... Sr Research Analyst at Edureka. A techno freak who likes to explore different technologies. Likes to follow the technology trends in market and write...
1 / 5 Blog from Introduction to Spring

In today’s fast paced world, we need everything to be quick. We don’t want to keep ourselves engaged in one work for too long, let it be anything like travelling, shopping, studying or working. When it comes to coding, we want our applications to be developed in the shortest period of time but providing full efficiency. We may be in a hurry, but still, we can neither compromise with our quality nor we want to put too much effort in it. So what’s the solution? Frameworks work the best in this situation. There are various Frameworks available out there in the market among which few are used like: Spring, Hibernate, Struts etc. Through this blog let’s find out what is Spring Framework and why it’s so popular in market!

Before starting, lets take a look at the topics I will be discussing in this blog:

Java Frameworks

Why we should go for Frameworks? Let’s understand it with our friend, Coddy.

Coddy in problem - What Is Spring Framework - Edureka!

                                                                                                                                                                                                                                                                                                                                                                                                                                             Coddy is given a task to develop an application, but the assigned time is not sufficient to finish it. He has to write a lot of lines of code (LOC) by himself. It’s very time consuming and tiring. He is confused what he should do! Where he should start from! 

Coddy thinks of solution - What Is Spring Framework - Edureka!

                                                                                                                                                                                                                                                            Coddy starts thinking of a solution to his problem. He needs something that is fast and efficient; saves time and effort, like something readymade. 

Coddy's Soln - What Is Spring Framework - Edureka!

                                                                                                                                                                                            Suddenly, the idea of using Frameworks strikes him. Frameworks are fast, efficient and light-weight. They are large bodies of predefined codes which we can easily add to our own code to solve a specific problem.

Coddy implementing - What Is Spring Framework - edureka!

                                                                                                                                                                                                                                                                                                                                                                                                                                                    He codes using the Framework. Surprisingly the code easily fitted with the framework.

Coddy's problem solved - What Is Spring Framework - Edureka!

                                                                                Coddy now, can code faster and complete his application within the given time frame. Moreover, he is free from writing thousands of lines of non-functional code.

coddy's Result - What Is Spring Framework - Edureka!

                                                                                                                                                                            After deploying the application which was developed using the Framework, he found that it executed with much higher speed and its throughput also increased when compared to other applications that were developed without using the Framework.

So, lets now begin with the Java Frameworks.

How Java Frameworks Came Into Existence?

Late in 1990’s the applications were widely developed using JEE standards. The premise of J2EE was multi-platform/ multi-vendor, if you can code according to the J2EE standards you can deploy your application on any J2EE application server irrespective of platform. Running your code on any application server provides you with many benefits like – transaction management, messaging, mailing, directory interface etc. But as nothing comes easy in this world, working with J2EE also had some difficulties. 

  • Very Complex: Enterprise Java Bean was developed for reducing the complexity in J2EE applications. But it didn’t succeed in its aim in implementation. Reason behind it is that, while writing a component it is required to write a set of XML files, home interfaces, remote/ local interfaces, etc.
  • ‘look-up’ problem: Whenever a component depended upon another component, it had to look up for the components it depended upon by itself. This component ‘look-up’ happens only by name, so the name of the dependency was hard-coded in the component.
  • Heavy weight: As all features like clustering, remoting, etc. were supported, you have to configure them, regardless of the fact that you need them or not. This will make your applications bloated.

This is how Java Frameworks came into existence. Java Frameworks are nothing but large bodies of predefined code which you can apply to your own code to solve your problem in a specific domain. You can use a framework by calling its methods, inheritance, by providing “callbacks”, listeners, or other implementations of the Observer pattern.

Let’s understand it through a pictorial representation:

Framework - What Is Spring Framework - Edureka

But how exactly they reduce our work and make our codes efficient? To understand it go through the following advantages and disadvantages of these frameworks. Let’s start with the advantages.                                                                                                                                                                                                                                                                                                                        

Efficiency - What Is Spring Framework - Edureka!

Efficiency:

Tasks that generally take you hours and hundreds of lines of code to compose, can now be done in minutes with pre-built functions. Development becomes a lot easier, so if it’s much easier, it’s much quicker, and subsequently more effective.

 security - What Is Spring Framework - Edureka!

Security:

An extensively used framework will generally have large security applications. The big benefit is the neighborhood behind that framework, where users usually end up being long-lasting testers. If you find a vulnerability or a security hole, you can go to the framework’s web site and let them know so that it can be fixed.        

             

                                                  Savings - What Is Spring Framework - Edureka!                                                                        Expense:

Most popular structures are complimentary and so it helps the developer to code faster. If the coding is done faster the expense for the final client will certainly be smaller in every aspect, be it time or effort. Moreover the maintenance cost is also low.

                                                                                                                                                                                                                                                         Support - What Is Spring Framework - Edureka!

Support:

As any other distributed tool, a framework generally includes documents, a support group or large-community online forums where you can acquire quick responses.

                                                                                                                                                                             

Despite having all these advantages Java Frameworks do have some disadvantages, like:

Restriction - What Is Spring Framework - Edureka!
Restrictions:

The framework’s fundamental behavior cannot be changed, indicating that when you use a framework, you are required to respect its limitations and work the way it is required. Thus, you must ensure that you choose a framework that fits your needs.                                                                                       

Code is public:Public - What Is Spring Framework - Edureka!

Since the framework is readily available to everyone, it is also offered to people with bad intentions. It can be studied in order to know how things work and to discover flaws that can be utilized against you.                                                                                                                                                                               

settings - What Is Spring Framework - Edureka!

Custom Features:

When you are making use of a framework, you know very little about the language behind it because the features in it are custom built. When you use custom built features, its very likely that you have to use them according to the framework’s standards which may differ from the original concept.                                                                                                                                                                                                                                                                                                                                                            

Now that you know the advantages and disadvantages of the frameworks, choose your framework according to your need. There are various kinds of frameworks available in the market. Below diagram shows a few of them:

JavaFrameworks - What Is Spring Framework - EdurekaSo, in this blog we will focus on Spring Framework.

What Is Spring Framework?

Here the question arises “What Is Spring Framework”? 

Spring Framework is a powerful lightweight application development framework used for Enterprise Java (JEE).

The core features of the Spring Framework can be used in developing any Java application. It can be described as complete and modular framework. The Spring Framework can be used for all layer implementations of a real time application. It can also be used for the development of particular layer of a real time application unlike Struts and Hibernate, but with Spring we can develop all layers.

This was about what is Spring Framework, but how it was developed? Well, there’s an interesting history behind it. Lets take a glance on Spring Framework’s history and origin.

In October 2002, Rod Johnson, an Australian computer specialist, wrote a book titled Expert One-on-One J2EE Design and Development. In this book he proposed a simpler solution based on ordinary Java classes (POJO) and dependency injection. He wrote over 30,000 lines of infrastructure code which included a number of reusable java interfaces and classes for developing the application. Around February 2003, Rod, Juergen and Yann started collaborating on the Spring project. The name “Spring” was given as it meant a fresh start after “Winter” of traditional J2EE.

Following is the timeline shown about major releases in the history of Spring :

Spring version history - What Is Spring Framework - Edureka!

It was named Interface 21, as a reference to 21st century and released under Apache 2.0 license. 
This was the first milestone release. Spring framework rapidly evolved since this release. Interface21 supported AspectJ parallely with Spring Framework.
New Features were added – extensible XML configs, support for Java 5 and dynamic languages, IoC extension points and AOP enhancements.
New features were added – support for Java 6/ JEE5, annotation configs, component auto-detection in classpath and OSGi compliant bundles.
New features were added – support for reorganized module system, SpEL, JavaConfig, embedded databases, REST support and support for Java EE 6.
Spring Data Commons Project was released. Later in 2012, Rod Johnson left the Spring team.
All Spring projects shifted to Pivotal. New features were added – full support for Java 8, websockets, higher third party library dependencies, groovy DSL for bean definitions.
It was compatible with Java 6, 7 and 8, with a focus on core refinements and modern web capabilities.
It will be the final generation within the general Spring 4 system requirements. 4.3.8 is the current version.

 

                                                                                                                                           

Why Spring Framework?

Below is a chart given which shows the comparison between Spring and various other Frameworks. spring comparison - What Is Spring Framework - Edureka!

Below is a graph based on a survey, as of May 2016. As you can see from the graph that Spring Framework is very popular in its domain and has continued to hold its position on top since 2014.Popular Frameworks - What Is Spring Framework - Edureka!

Reasons for Spring Frameworks’s popularity

There are generally three main reasons for Spring Framework’s popularity.

  1. Simplicity
  2. Testablity
  3. Loose Coupling

Let’s discuss these topics in details.

Simplicity: Spring Framework is simple because its non-invasive as it uses POJO and POJI models.<>

  • POJO (Plain Old Java Objects): A Java class not coupled with any technology or any framework is called POJO.
  • POJI (Plain Old Java Interfaces): A Java interface not coupled with any technology or any frame work is called POJI.

TestablityFor writing the Spring application, server is not mandatory. But for struts and EJB applications, you need a server, if you want to test the application. It may need lot of changes in the source and to view those changes, each time you have to restart the server. This becomes tedious and time consuming. In case of Spring Framework, it has it’s own container to run the applications.ioc - What Is Spring Framework - Edureka!

Loose Coupling : Spring Framework is loosely coupled because it has concepts like Dependency Injection, AOP etc. These features help in reducing dependency and increasing the modularity within the code. Lets understand this with an example.

Here I have a Bike interface which has a start() method. It is further implemented by three classes, namely : Yamaha, Honda and Bajaj.interface implemetation - What Is Spring Framework - Edureka!

public interface Bike
{
public void start();
}

Here a class Rider creates an object of any class which implements the Bike interface.

class Rider
{
Bike b;
public void setBike(Bike b)
{
this.b = b;
}
void ride()
{
b.start();
}
}

Now the Spring Framework container can inject an object of any class that implements Bike interface, according to the requirement. This is how loose coupling works. 

Spring Framework Architecture

Spring Framework Architecture - Spring Interview Questions - Edureka!

As you can see from the above diagram that Spring has a layered architecture consisting of different modules which have their own functionality. These modules are generalized into following layers:

  • Core Container
  • Data Access/ Integration
  • Web
  • AOP (Aspect Oriented Programming)
  • Instrumentation
  • Test.

You might be wondering, what is Spring Framework’s advantage of having layered architecture? Let’s find out through following points:

  • Spring Framework effectively organizes your middle tier objects.
  • Irrespective of the runtime environment, Spring Framework’s configuration management services can be used in any architectural layer.
  • Spring Framework handles the configuration in a consistent way throughout the application. This eliminates the need to use a variety of custom-property file formats.
  • Spring Framework is designed in such a way that applications built with it will depend on as few of its APIs as possible.
  • Because of the use of interfaces, Spring Framework facilitates good programming practice.

To completely understand what is Spring Framework, let’s see one simple Spring Framework Application. Follow the five simple steps:

Step I: Creating the Bean class


package org.edureka.firstSpring;

public class StudentBean 
{ 
 String name; 
 public String getName()
 { 
 return name; 
 } 
 public void setName(String name) 
 { 
 this.name = name; 
 } 
 public void displayInfo()
 { 
 System.out.println("Hello: "+ name); 
 } 
}

Step II: Create an XML file


<xml version="1.0" encoding="UTF-8">
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> 
<bean id="studentbean" class="org/edureka/firstSpring/StudentBean"> 
<property name="name" value="Edureka"></property>
</bean>
</beans>

Step III: Create the main class


 package org.edureka.firstSpring;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 public class StudentDemo
 {
 public static void main(String[] args)
 {
 ApplicationContext appCon=new ClassPathXmlApplicationContext("StudentConfig.xml");
 StudentBean factory=(StudentBean)appCon.getBean("studentbean");
 factory.displayInfo();
 }
 }

Step IV: Load the jar files

Load the following jar files.

  • commons-logging-1.2.jar 
  • javax.servlet-api-3.1.0.jar 
  • jstl-1.2.jar
  • spring-aop-4.2.2.RELEASE.jar 
  • spring-beans-4.2.2.RELEASE.jar 
  • spring-context-4.2.2.RELEASE.jar 
  • spring-core-4.2.2.RELEASE.jar
  • spring-expression-4.2.2.RELEASE.jar
  • spring-web-4.2.2.RELEASE.jar 
  • spring-webmvc-4.2.2.RELEASE.jar

NOTE: In case you need the jar files, comment below.

Step V: Run the program

Run the program on your server to test the application.

Hope I was able to explain clearly, what is Spring Framework, how exactly does it work and what is it used for. You also refer to the video on “What Is Spring Framework”, where the instructor describes the topics discussed in this blog along with practical demonstration.

What Is Spring Framework In Java | Spring Framework Tutorial | Edureka

If you are interested in learning more about the Spring Framework, then stay tuned to this blog series of mine because I will be coming up with another blog on Spring Tutorial which will talk about more advanced concepts in Spring.

If you want to learn Spring and wish to use it while developing Java applications, then check out the Spring Framework Course by Edureka, a trusted online learning company with a network of more than 250,000 satisfied learners spread across the globe.

Got a question for us? Please mention it in the comments section and we will get back to you.

Comments
0 Comments

Join the discussion

webinar REGISTER FOR FREE WEBINAR
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP

Subscribe to our Newsletter, and get personalized recommendations.

image not found!
image not found!

What Is Spring Framework? – Path To Efficient Development

edureka.co