Skip to main content

Introduction to Spring

If we talk about Java EE development then the biggest buddy that comes into the picture is Spring. So in this article, I am going to cover some brief introduction of Spring framework and then we are going to look why Spring is so popular, and in subsequent articles, I am going to cover more about Spring.

So what is Spring
  • Spring is a Lightweight, Open Source, Free to use application framework that provides comprehensive infrastructure support for developing Java-based enterprise applications. Spring handles the infrastructure and configurations so you can focus on your application.
  • It was written by Rod Johnson in June 2003 and first released under the Apache 2.0 license, And now maintained by Pivotal.
  • Spring have not reinvented everything from the scratch but it has integrated some existing technologies and frameworks like Hibernate, Struts, JSF, EJB, and more in an efficient modular architecture by integrating them very efficiently. You can use what you need and can leave those you don’t need now.
    That’s why some developers also call Spring “A framework of frameworks”, because Spring allows them to use all popular frameworks combinedly.
  • The Spring Framework consists of features organized into about 20 modules. These modules are grouped into Core Container, Data Access/Integration, Web, AOP (Aspect Oriented Programming), Instrumentation, Messaging, and Test, as shown in the following diagram.
    spring modules
  • Lightweight IoC container and Transaction support have also made Spring the best replacement for costly EJB containers.
  • Spring Enables to develop enterprise applications using POJO Programming. By using POJO programming developer don’t need any EJB Container in our Application Server Instead of that only a robust Servlet Container is good. POJO programming also enables continuous integration and testability.

Why Spring is so popular
Spring became so popular in its early days because of these features
  • Lightweight: Spring is lightweight when it comes to size and transparency,
    • The basic version of spring framework is around 1MB.
    • Processing overhead is also very negligible.
    • Due to its modular architecture, you have the option to choose what you want to include and what’s not.
    • You can also call Spring lightweight as compared to heavyweight EJB containers.
  • Loose Coupled code through Dependency Injection: Loose coupling is achieved in Spring using the technique Inversion of Control. The objects give their dependencies instead of creating or looking for dependent objects.
  • Spring Core Container or IoC Container: Central to the Spring framework is its Ioc Container which contains and manages the lifecycle and configuration of application objects. Objects created by the container are also called managed objects or beans.
  • Aspect-oriented Programming (AOP): Spring supports Aspect Oriented Programming and enables cohesive development by separating application business logic from system services.
  • MVC Framework: Spring comes with MVC web application framework (Spring MVC), built on core Spring functionality. This framework is highly configurable via strategy interfaces and accommodates multiple view technologies like JSP, Velocity, Tiles, iText, and POI. But other frameworks can be easily used instead of Spring MVC Framework.
  • Transaction Management: Spring provides a declarative transaction management interface that can scale down to a local transaction (using a single database e.g.) and scale up to global transactions (using JTA e.g.). This allows the developer to add the pluggable transaction managers and making it easy to demarcate transactions without dealing with low-level issues. Spring’s transaction support is not tied to J2EE environments and it can be also used in the container-less environments.
  • Convenient Exception Handling: Spring provides a convenient API for translating technology-specific exceptions (thrown by JDBC, Hibernate, or JDO e.g.) into consistent, meaningful, unchecked exceptions which describe more about itself.

Comments

Popular posts from this blog

What is Variable Shadowing and Hiding in Java

Java allows us to declare a variable whenever we need it, We can categorize all our variables into 3 categories which have different-different scopes Instance Variables - Defined inside a class and have object level scope. Class Variables - Defined inside a class with static keyword, have class level scope common to all objects of the same class Local Variables - Defined inside a method or in any conditional block, have the block-level scope and only accessible in the block where it defined. What is Variable Shadowing Variable shadowing happens when we define a variable in a closure scope with a variable name and we have already defined a variable in outer scope with the same name. In other words, when a local variable has the same name as one of the instance variable, the local variable shadows the instance variable inside the method block. In the following example, there is an instance variable named x and inside method printLocalVariable(), we are shadowing it by the local ...

Why String is Immutable and Final in Java

While coding in any programming language we always require some predefined types which we can use to write the code and every programming language provides these types in its way e.g. Java provides primitive types ( int, long, char float etc) and reference types (custom types like Object, String, Thread ). For string manipulation, Java provides a class java.lang.String which gives us a way to create string objects and provides different behaviors to operate on those objects e.g. replace(), length() String name = "Naresh"; System.out.print(name.length()); System.out.print(name.isEmpty()); Whenever we talk about String class in Java we say it is i mmutable in nature and all string literals are stored in String Constant Pool (SCP) . Prior to Java 7 String Constant Pool belongs to Permanent Generation area of heap which means Garbage Collector will not touch it in normal scenarios. But from Java 7 onwards string constant pool is not part of Perm Gen but live with o...

Creating objects through Reflection in Java with Example

In Java, we generally create objects using the new keyword or we use some DI framework e.g. Spring to create an object which internally use Java Reflection API to do so. In this Article, we are going to study the reflective ways to create objects. There are two methods present in Reflection API which we can use to create objects Class.newInstance() → Inside java.lang package Constructor.newInstance() → Inside java.lang.reflect package However there are total 5 ways create objects in Java, if you are not aware of them please go through this article 5 Different ways to create objects in Java with Example . Both Class.newInstance() and java.lang.reflect.Constructor.newInstance() are known as reflective methods because these two uses reflection API to create the object. Both are not static and we can call earlier one on a class level object while latter one needs constructor level object which we can get by using the class level object. Class.newInstance() The Class class is th...