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

How Does JVM Handle Method Overloading and Overriding Internally

In my previous article Everything About Method Overloading Vs Method Overriding , I have discussed method overloading and overriding, their rules and differences. In this article, we will see How Does JVM Handle Method Overloading And Overriding Internally, how JVM identifies which method should get called. Let’s take the example of parent class  Mammal and a child  Human classes from our previous blog to understand it more clearly. public class OverridingInternalExample { private static class Mammal { public void speak() { System.out.println("ohlllalalalalalaoaoaoa"); } } private static class Human extends Mammal { @Override public void speak() { System.out.println("Hello"); } // Valid overload of speak public void speak(String language) { if (language.equals("Hindi")) System.out.println("Namaste"); else System.out.println("Hello"); } @...

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 ...

AutoWiring Spring Beans Into Classes Not Managed By Spring Like JPA Entity Listeners

In my previous article JPA Auditing: Persisting Audit Logs Automatically using EntityListeners , I have discussed how we can use Spring Data JPA automate Auditing and automatically create audit logs or history records and update CreatedBy, CreatedDate, LastModifiedBy, LastModifiedDate properties. So in order to save history records for our File entity, we were trying to auto-wire EntityManager inside our FileEntityListener class and we have come to know that we can not do this. We can not inject any Spring-managed bean in the EntityListener because EntityListeners are instantiated by JPA before Spring inject anything into it. EntityListeners are not managed Spring so Spring cannot inject any Spring-managed bean e.g. EntityManager in the EntityListeners. And this case is not just with EntityListeners, you can not auto wire any Spring-managed bean into another class (i.e. utility classes) which is not managed by Spring. Because it is a very common problem and can also arise with other c...