Spring FrameWork

Spring handles the infrastructure so you can focus on your application.

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 that enables the developers to create Web applications whose components are loosely coupled

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.


New Features and Enhancements in Spring Framework 4.3

The Spring Framework was first released in 2004,since then there have been significant major revisions.

Core Container Improvements:

It is no longer necessary to specify the @Autowired annotation if the target bean only defines one constructor.

@PersistenceContext/@PersistenceUnit selects a primary EntityManagerFactory bean if declared as such.

@Scheduled and @Schedules may now be used as meta-annotations to create custom composed annotations with attribute overrides.

Caching Improvements:

SpEL expressions in caches-related annotations can now refer to beans (i.e. @beanName.method()).

Web Improvements:

Built-in support for HTTP HEAD and HTTP OPTIONS.

New @RestControllerAdvice annotation with combined @ControllerAdvice with @ResponseBody semantics.

WebSocket Messaging Improvements:

@SendTo and @SendToUser can now be specified at class-level to share a common destination.

Support for new library and server generations:

Hibernate ORM 5.2 (still supporting 4.2/4.3 and 5.0/5.1 as well, with 3.6 deprecated now).

The Spring framework

  • Aims to overcome the problems by enabling the use of simple JavaBeans (POJOs "plain old Java objects") to implement the business logic for Web applications.
  • Aims to minimize the dependence of application code on its framework.
  • The Spring applications are not required to perform API lookup.

Popularity Of Spring is due to

  • Simplicity
  • Testability
  • Loose Coupling
  • Predefined Templates
  • Abstraction

Simplicity :Spring framework is simple because as it is non-invasive, POJO and POJI model

Testability :In Spring, for testing spring application server is not mandatory.Spring has it own container to run the applications.

Spring can be used to develop any kind of java application, means we can develop starting from console application to enterprise level application.

Loose Coupling :In spring objects are loosely coupled,this is the core concept of spring framework.

Predefined Templates : Spring framework provides templates for JDBC, Hibernate, JPA etc. technologies. So there is no need to write too much code. It hides the basic steps of these technologies.

Let's take the example of JdbcTemplate, you don't need to write the code for creating connection, creating statement, committing transaction, closing connection, exception handling etc. You need to focus on business login.Thus, it save a lot of JDBC code.

Abstraction :It provides powerful abstraction to JavaEE specifications such as JMS, JDBC, JPA and JTA.

Features Of spring Framework

Spring is a modular framework and has the following features:

  • Pluggability
  • Dependency Injection (DI)
  • Aspect-Oriented Programming (AOP)
  • Container
  • Lightweight

Pluggability

  • Spring allows you to associate business layer objects with each other, using XML configuration files.
  • When the application is executed, Spring automatically creates and instantiates all the object relationships on demand.
  • In a Spring-enabled application, you can plug in new services or modify existing ones easily.
  • These application objects are, therefore, called pluggable objects.

Dependency Injection (DI)

  • The Spring framework promotes the concept of loose coupling through DI.
  • With DI, you do not need to create the business layer objects yourself or associate them with each other in your code.
  • The Spring framework creates the business layer objects and associates them with each other, as defined in the configuration file.
  • DI eliminates the need for code lookup, allows pluggability and reuse of existing code, and eases maintenance and testing of the application.

Aspect-Oriented Programming (AOP)

  • It separates the application logic from the system-level services, such as transaction management, logging, and security.
  • These services are called cross-cutting concerns as they cut across a wide range of objects within the application.
  • It is used to modularize and separate these concerns in the form of aspects.
  • Aspect is defined as modularization of the system wide concerns whose implementations cut across multiple objects within the application.
  • An aspect encapsulates a behavior that needs to be implemented in multiple objects of the application.

Container

  • The Spring framework is a container that holds all the application objects.
  • It is also responsible for managing the life cycle and configuration of all the application objects.
  • You only need to describe how the application objects will be created, configured, and associated with each other.
  • The container will create those objects and associate them together.

Lightweight

  • Spring is a lightweight framework that makes it easy to configure and create complex applications.
  • It consists of several well-defined modules, built upon the concept of DI and AOP.
  • These modules provide a platform for writing loosely coupled application code.
  • The developer has the choice of using all the modules or any specific module, as per the application requirements.