Introduction to Spring Framework

Introduction to Spring Framework
January 24, 2017 No Comments Uncategorized Vikram Patil

Spring Framework 1The spring framework is a lightweight, open source java platform provides comprehensive infrastructure support for developing Java applications. It was initially written by Rod Johnson and released in 2003. Today millions of developers around the world use spring framework to develop java application. Spring framework is a 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.

Features:
• Lightweight: spring is lightweight framework when it comes to size and transparency. The basic version of spring framework is around 2MB.

• Inversion of Control(IOC): IOC makes the code loosely coupled. There is no need to modify the code if our logic is moved to new environment. IOC container is responsible to inject the dependency. We provide metadata to the IOC container either by XML file or annotation.

• Aspect oriented(AOP): Spring supports Aspect oriented programming . AOP breaks the program logic into distinct parts , used to increase modularity called cross-cutting concerns. These are conceptually separate from the application’s business logic.

• MVC Framework: Spring framework supports model, view and controller web application framework. This framework is highly configurable via strategy interfaces, and accommodates multiple view technologies like JSP.

• JDBC Exception Handling: JDBC is a technique to connect to the database and execute SQL queries. The JDBC abstraction layer of the Spring offers a meaningful exception hierarchy. Which simplifies the error handling strategy.

Architecture :

Spring Framework 2

Core Container:
The core container contains spring-core, spring-beans, spring-context, spring-context-support, spring-expression modules.

Core: Core module is a fundamental part of spring framework, support Inversion of Control and Dependency Injection.
The Dependency Injection is a design pattern that removes the dependency of the programs. Dependency Injection makes code loosely coupled, which is easy for testing. In such case we provide the information from the external source such as XML file. In spring framework dependency injection perform in two ways.

1. Construction Injection: This DI method will injects the dependency via a constructor. A bean configuration file to declare the beans and set the dependency via constructor injection using tag.

2. Setter Injection: This DI method injects the dependency via a setter method. This is the popular and simple DI method. In this method A helper class with a setter method and A bean configuration file to declare the beans and set the dependency via setter injection using property tag.

Beans: Beans module provides BeanFactory which is a factory pattern, separates the dependencies like initialization, creation and accessal program logic.

Context: This module builds on base of Core and Beans module. The Context module inherits its features from the Beans module and adds support for resource loading, event propagation. The ApplicationContext interface used for the context module.

SpEL: The spring-expression module provides expression language for querying and manipulating an object at runtime. It’s supports setting and getting property values, method invocation, accessing the content of arrays, logical and arithmetic operators and retrieval of objects by name from Spring’s IoC container.

AOP:
The spring-aop module provides aspects oriented programming implementation. It’s allow to define method-interceptors and pointcuts to cleanly decouple code that implements functionality that should be separated.
Spring Security:
Spring Security is a flexible and powerful authentication and access control framework to secure Spring-based Java web application. The Spring security provides a method for making authenticated HTTP requests using a token – an identifier used to denote an access grant with specific scope, duration, and other attributes. There are two major areas of security are –
1. Authentication: Authentication is a process of checking the user, who they claim to be.
2. Authorization: Authorization is a process of deciding an user is allowed to perform an activity within the application.

Aspects:
The spring-aspects module provides integration with AspectJ. It’s a another powerful aspect oriented programming framework.

Instrumentation:
The spring-instrument ass instrumentation and implementation of classloader which is used for application servers creation.

Messaging:
Spring framework includes spring-messaging module with key abstraction from the spring integration. This module includes a set of annotations for mapping messages to methods, similar to the Spring MVC annotation based programming model.

Data Access/Integration:
This layer consisand Transaction module.

JDBC: spring-jdbc module provides a JDBC abstraction layer which is removes the tedious JDBC related code.

ORM: spring-orm module is . It provides integration layers for popular object-relational mapping APIs, including JDO, Hibernate.

OXM: spring-oxm module supports to object/xml mapping implementation like XMLBeans, JAXB, Castor.

JSM: spring-jsm module contains fratures for producin called Java Messaging Services.

Transaction: spring-tr module supports programmatic and declarative transaction management for classes that implement special interfaces and for all your POJOs.
Transaction Management:
Sequence of database action that will be performed to complete operation and its management is known as Transaction Management. The combination of all this actions treated as a single action. In J2EE, Transaction Management can be divided in two types.
1. Global Transaction: Global transaction use to work with multiple transaction resources like RDBMS. Global transaction management is required in a distributed computing environment where all the resources are distributed across multiple systems.
2.Local Transaction: Local transactions are specific to a single transactional resource like a JDBC connection. Most of web application uses only single resources hence it is best option to use in normal app.

Web :
This layer of spring framework consists spring-web, spring-webmvc, spring-webmvc-portlet, spring-websocket modules.

Web: spring-web module provides web oriented integration like multipart file upload, initialization of IoC container and web oriented application context.

Web-MVC: spring-webmvc supports for model-view-controller implementation for spring web application.Spring MVC pattern separate the input logic, business logic, and UI logic while providing a loose coupling between these elements.
Model: Model consists of POJO classes and the application data.

View: View render the model data and generate HTML output on client’s browser.

Controller: The Controller is typically implements the business services to perform some action and responsible for processing user requests and building appropriate model and passes it to the view for rendering.

In Spring Web MVC, DispatcherServlet class works as the front controller. It is responsible to manage the flow of the spring mvc application.

WebSocket: spring-websocket module supports for web based two way communication between client and server in web application.

Portlet: web-mvc-portlet module supports for model-view-controller implementation in portlet envoirnment and mirror the funcationality of web-mvc module .

Testing:
The spring-test module supports to integration and unit testing.

Remote Access Framework:
Remote services hosted on remote servers and accessed by clients over the network. Spring features integration classes for remoting support using various technologies. The remoting supports development of remote-enabled services, implemented by POJO classes. There are the four remoting ways supported by spring.
1. RMI(Remote Method Invocation): Use RMI to invoke a remote method.

2. Hessian: Transfer binary data between the client and the server.

3. Burlap: Transfer XML data between the client and the server.

4. JAX-WS: Java XML API for Web Services.

About The Author

Leave a reply

Your email address will not be published. Required fields are marked *