Learnitweb

Introduction to Spring Framework

Spring was developed by Rod Johnson. The first version of Spring was released in October 2002.

Spring is a lightweight framework for creating Java applications. Spring can be used to create web as well as stand-alone Java application.

In the above statement, when we say that Spring is lightweight, we don’t mean to say that Spring requires less number of classes or the size of the distribution is less. What this statement means is, we can use Spring Core in our project with minimum changes.

Spring’s core is based on the principle of Inversion of Control. Inversion of Control can be explained in simple words as ” The code declares what it needs to execute properly (i.e. its dependencies) and the container creates and manages the dependencies”. We can say that, Inversion of Control externalizes the creation and management of dependencies. There is another term ‘Dependency Injection’ which is discussed with Inversion of Control. In Spring’s context, both can be used interchangeably.

Spring’s dependency injection is based on two Core Java concepts: Interfaces and Java Beans.

Spring provides flexibility to define dependency configuration in XML files, annotations, Java configuration classes or Groovy bean definition method.

Modules

For almost every programming feature requirement, Spring provides a module. There are about 20 modules in Spring framework. These modules are grouped into Core Container, Web, AOP (Aspect Oriented Programming), Data Access/Integration, Instrumentation, Messaging, and Test.

  • IoC Container – IoC Container consists of the Core, Beans, Context, and Expression Language modules.
  • Test – The Test module supports the testing of Spring components with JUnit or TestNG. It also provides mock objects that you can use to test your code in isolation.
  • Web – The Web layer consists of the Web, Web-Servlet, WebSocket and Web-Portlet modules. Web module provides basic web-oriented integration features such as file upload functionality and initialization of IoC container using servlet listeners and a web-oriented application context.
  • Data Access/Integration – The Data Access/Integration layer consists of the JDBC, ORM, OXM, JMS and Transaction modules. Spring provides features like JDBC-abstraction layer. Integration layers for popular object-relational mapping APIS like JPA and Hibernate. The OXM module provides an abstraction layer that supports Object/XML mapping implementations for JAXB, Castor, XMLBeans, JiBX and XStream. The Java Messaging Service (JMS) module contains features for producing and consuming messages. The Transaction module supports programmatic and declarative transaction management.
  • AOP – Aspect-oriented programming implementation allowing you to define, for example, method-interceptors and pointcuts to cleanly decouple code that implements functionality that should be separated.
  • Aspects – Aspects module provides integration with AspectJ.
  • Instrumentation – The Instrumentation module provides class instrumentation support and classloader implementations to be used in certain application servers.
  • Messaging – The Java Messaging Service (JMS) module contains features for producing and consuming messages.

Features of Spring

  • Lightweight: Spring framework is lightweight. It means the Spring core can be integrated in our project with minimum changes.
  • Uses Inversion of Control: It reduces glue code. The code can just to declare what it needs to execute. This promotes loose coupling as the dependency can be changed later without much effort.
  • Can be used to develop web as well as desktop applications.
  • Easy to test: Dependency injection makes easy to test applications developed in Spring.
  • Provides almost all common programming features like validation, internationalization, data binding, data access, MVC frameworks, integration JMS, email, scheduling, cache and many more.
  • Languages: Supports Kotlin, Groovy, dynamic languages.