Introduction of Spring Framework:-
Spring is an open source framework created to address the complexity of enterprise application development. One of the chief advantages of the Spring framework is its layered architecture, which allows you to be selective about which of its components you use while also providing a cohesive framework for J2EE application development
Spring enables you to build applications from “plain old Java objects” (POJOs) and to apply enterprise services non-invasively to POJOs. This capability applies to the Java SE programming model and to full and partial Java EE.
Spring framework is an open source Java platform and it was initially written by Rod Johnson and was first released under the Apache 2.0 license in June 2003.
Spring is lightweight when it comes to size and transparency. The basic version of spring framework is around 2MB.
The core features of the Spring Framework can be used in developing any Java application, but there are extensions for building web applications on top of the Java EE platform. Spring framework targets to make J2EE development easier to use and promote good programming practice by enabling a POJO-based programming model.
History of Spring Framework :-
1 Year 2002, Rod Johnson release it's first version
2 March 2004, first version release under Apache 2.0 license
3 In Year 2004 and 2005 further milestone release was make available to the developers
4 Year 2006 Spring 1.2.6 released
5 In December 2009, version 3.0 GA was released
6 June 15, 2010, Spring 3.0.3 released
Advantages of Spring Framework:-
1 Spring is Lightweight container
2 No App Server Dependent – like EJB JNDI Calls
3 Objects are created Lazily , Singleton - configuration
4 Components can added Declaratively
5 Initialization of properties is easy – no need to read from properties file
6 Declarative transaction, security and logging service - AOP
7 application code is much easier to unit test
8 With a Dependency Injection approach, dependencies are explicit, and evident in constructor or JavaBean properties
9 Spring's configuration management services can be used in any architectural layer, in whatever runtime environment.
10 Spring can effectively organize your middle tier objects
11 Not required special deployment steps.
12 Spring has layered architecture. Use what you need and leave you don't need now.
13 Spring Enables POJO Programming. There is no behind the scene magic here. POJO programming enables continuous integration and testability.
14 Dependency Injection and Inversion of Control Simplifies JDBC
15 Spring is aOpen source and no vendor lock-in.
Features of Spring:-
spring is lightweight when it comes to size and transparency. The basic version of spring framework is around 1MB. And the processing overhead is also very negligible.
2 Inversion of control (IOC):
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.
3 Aspect oriented (AOP):
Spring supports Aspect oriented programming and enables cohesive development by separating application business logic from system services.
Spring contains and manages the life cycle and configuration of application objects.
5 MVC Framework:
Spring comes with MVC web application framework, 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.
6 Transaction Management:
Spring framework provides a generic abstraction layer for transaction management. This allowing 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 container less environments.
7 JDBC Exception Handling:
The JDBC abstraction layer of the Spring offers a meaningful exception hierarchy, which simplifies the error handling strategy. Integration with Hibernate, JDO, and iBATIS: Spring provides best Integration services with Hibernate, JDO and iBATIS
Core Concept of Spring:- Spring have some Important Core Concept as follows
1 IOC (or Dependency Injection) :
The basic concept of the Inversion of Control pattern (also known as dependency injection) is that you do not create your objects but describe how they should be created. You don't directly connect your components and services together in code but describe which services are needed by which components in a configuration file. A container (in the case of the Spring framework, the IOC container) is then responsible for hooking it all up.
i.e., Applying IoC, objects are given their dependencies at creation time by some external entity that coordinates each object in the system. That is, dependencies are injected into objects. So, IoC means an inversion of responsibility with regard to how an object obtains references to collaborating objects.
2 Aspect Oriented Programming(AOP):
AOP in spring allows cross cutting of concerns. AOP is not dependent on Spring’s IOC container. The key unit of modularity in OOP(Object Oriented Programming) is the class, whereas in AOP the unit of modularity is the aspect. Spring AOP is implemented in pure java and hence does not require a separate compilation process.
The key unit of modularity in OOP is the class, whereas in AOP the unit of modularity is the aspect. Whereas DI helps you decouple your application objects from each other, AOP helps you decouple cross-cutting concerns from the objects that they affect.
The AOP module of Spring Framework provides aspect-oriented programming implementation allowing you to define method-interceptors and pointcuts to cleanly decouple code that implements functionality that should be separated.
The Spring Framework uses Spring AOP internally for transaction management, security, remote access, and JMX.
Since version 2.0 of the framework, Spring provides two approaches to the AOP configuration:
1 schema-based approach
2 @AspectJ-based annotation style.