0% found this document useful (0 votes)
156 views30 pages

Spring Introduction

Spring is a powerful and popular Java application development framework. It provides lightweight and modular libraries that help developers create robust, easily testable code. Some key features of Spring include dependency injection, aspect-oriented programming, and support for common web development patterns like MVC. The Spring ecosystem includes modules for web applications, data access, integration testing, and more.

Uploaded by

M.I.M KRUPHA
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
0% found this document useful (0 votes)
156 views30 pages

Spring Introduction

Spring is a powerful and popular Java application development framework. It provides lightweight and modular libraries that help developers create robust, easily testable code. Some key features of Spring include dependency injection, aspect-oriented programming, and support for common web development patterns like MVC. The Spring ecosystem includes modules for web applications, data access, integration testing, and more.

Uploaded by

M.I.M KRUPHA
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 30

SPRING INTRODUCTION

INTRODUCTION:

Java frameworks provide the various framework to make the programs optimized and highly
efficient.
The available framework are: Spring ,JSF ,Hibernate ,play ,Strunt ,Maven .

Spring is the powerful lightweight application development framework. It contains predefined


API which can embed in our programs.

Spring is the most popular application development framework for enterprise Java. Millions of
developers around the world use Spring Framework to create high performing, easily testable,
and reusable code.

Spring framework is an open source Java platform. 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.
FRAMWORK PRINCIPLE:

This frame work follows abides Hollywood principle that is “Don’t call us we’ll call you” also
called as Inversion of Control(IoC).

It is available in source forge since 2003.it is complete and modular framework for developing
enterprise at February 2003.

General concepts on spring:

Dependency:
It is the concept of class in the program dependent on the other for its functionality or working.

Injection:
It is the concept in which the dependent class is injected with the class in which it is dependent.

Spring can be used for all Layer implementation for real time or in particular layer.
FEATURES :

• Open Source
• Comprehensive tool
• Light Weight
• Solves Problems.
• Framework of Frameworks.
• Avail array of resources.

WHY SPRING?
• Simplicity
Simple because it is non-invasive it uses POJO(Plain Old Java Object),POJC and POJI.
• Testability
Writing spring application POJO is used and server is not mandatory, because it has it’s
own container.
• Loose coupling
Spring objects are loosely coupled.
SPRING FRAMEWROK ECOSYSTEM

the Spring Framework Ecosystem into five parts:


1) Web layer, 2) Common layer, 3) Service layer, 4) Data layer and 5) Foundation
WEB LAYER:

The Spring projects available in this layer will help you with your front-end development in one
way or the other.

•Spring HATEOAS
•Spring Mobile
•Spring Web Flow
•Spring Session
•Spring Web Services
•Spring Social
•Spring for Android
•Spring Security

Spring Security at the center of all these projects for a reason. It just implies that all web layer
projects can make use of Spring Security.

Spring Session allows you to handle web sessions in your application.


Spring Web Services helps you build a contract-first SOAP-based web service. It also helps you
consume an SOAP-based web service with Spring.
It is written on WSDL (Web Services Description Language) first. It defines the contract.

Spring Social This eliminates the need for a user to create a new account for your application.
Including it in your application involves setting up configurations based on providers. It is a
standard set of code that you write once.

Spring for Android helps you build native android applications.

Spring HATEOAS helps your create REST representations that follow HATEOAS principle. Spring
HATEOAS sits on top of Spring web-MVC. It has no other dependency which makes it easy to
introduce or pull it out of your projects.

Spring Mobile helps you build mobile friendly pages. It can detect if your requests are coming from
a mobile device.

Spring Web Flow splits data into many screens for easy navigation.
Spring Security is at the heart of this layer. If you are writing a web application,  you will need to
interact with a robot or a user at some point. Spring Security makes your application secure. It
controls who can interact with your application and at what levels.
Spring Security is almost irreplaceable.

COMMON LAYER:

A Spring Framework has 20 modules. These twenty modules fall under six categories.
1) Spring Web
2) Spring Test
3) Spring Data Access/Integration
4) Spring AOP and Instrumentation
5) Spring Messaging
6) Spring Core Container

All Spring Projects make use of one or more of these modules.


SERVICE LAYER:

Spring Integration Spring Integration is perfect for handling event-based actions. It can be


plugged on top of any Spring Data layer projects.

Spring Cloud A POM in maven is a Project Object Model. It contains all the libraries your
application needs. If you use maven in your application, this is your pom.xml.
Spring Cloud projects could have intricate dependencies. Instead of letting Spring developers
meddle with versions, Spring Cloud put together a BOM.
A BOM has in it defined all the libraries and their versions that a developer will need to pull.
A project leveraging Spring Cloud would bring this BOM into dependencyManagement in its POM.
Now you could bring a Spring Cloud subproject into your application. And the BOM would take care
of the versions.

DATA LAYER:

Spring AMQP(Advanced Message Queuing Protocol)


Spring AMQP abstracts out dealing with sending and receiving messages. It provides a low-level
template to interact with data. It provides a connection factory. It provides a pre-built
implementation in RabbitMQ.
Spring LDAP(Lightweight Directory Access Protocol)
Create a service to look up users’ roles and swap it as an implementation to do authorization.

Spring Data Spring Data, like Spring Cloud, is another umbrella project with many wonderful
offerings. Spring Data ais a common API to do CRUD operations for different databases. It has
support for all the popular SQL as well as NoSQL databases.

Spring Batch
Spring Batch is a framework with lots of features. And it requires commitment.
Spring Batch can do any bulk processing job. These are long running queries that you need running
in the background.

FOUNDATION LAYER:
they serve as a foundation for other Spring Projects

Spring IO Platform
Spring IO makes it easy to bring in what you need for your application.
Spring IO Platform provides Spring Boot under its belt.
Spring Boot
It is the easiest way to build and run your application. It gives you a command line tool to build
an application in shortest time frame.

Spring XD Spring XD provides a way to build and manage big data applications. Spring XD also
helps you perform big data analytics on these applications.

ARCHITECTURE OF SPRING:

This contains totally 20 modules and each of these


modules is categorized into five:

• Test
• Core container
• Miscellaneous
• Data Access/Integration
• Web
Core Container
The Core Container consists of the Core, Beans, Context, and Expression Language modules the
details of which are as follows −

•The Core module provides the fundamental parts of the framework, including the IoC and
Dependency Injection features.

•The Bean module provides BeanFactory, which is a sophisticated implementation of the factory


pattern.

•The Context module builds on the solid base provided by the Core and Beans modules and it is a
medium to access any objects defined and configured. The ApplicationContext interface is the focal
point of the Context module.

•The SpEL module provides a powerful expression language for querying and manipulating an object
graph at runtime.
Data Access/Integration:
The Data Access/Integration layer consists of the JDBC, ORM, OXM, JMS and Transaction
modules whose detail is as follows −

•The JDBC module provides a JDBC-abstraction layer that removes the need for tedious JDBC
related coding.

•The ORM module provides integration layers for popular object-relational mapping APIs, including
JPA, JDO, Hibernate, and iBatis.

•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 for


classes that implement special interfaces and for all your POJOs.
Web
The Web layer consists of the Web, Web-MVC, Web-Socket, and Web-Portlet modules the details of which
are as follows −

•The Web module provides basic web-oriented integration features such as multipart file-upload


functionality and the initialization of the IoC container using servlet listeners and a web-oriented application
context.

•The Web-MVC module contains Spring's Model-View-Controller (MVC) implementation for web


applications.

•The Web-Socket module provides support for WebSocket-based, two-way communication between the


client and the server in web applications.

•The Web-Portlet module provides the MVC implementation to be used in a portlet environment and


mirrors the functionality of Web-Servlet module
Miscellaneous
There are few other important modules like AOP, Aspects, Instrumentation, Web and Test modules
the details of which are as follows −

•The AOP module provides an aspect-oriented programming implementation allowing you to define


method-interceptors and pointcuts to cleanly decouple code that implements functionality that
should be separated.

•The Aspects module provides integration with AspectJ, which is again a powerful and mature AOP
framework.

•The Instrumentation module provides class instrumentation support and class loader


implementations to be used in certain application servers.

•The Messaging module provides support for STOMP as the WebSocket sub-protocol to use in


applications. It also supports an annotation programming model for routing and processing STOMP
messages from WebSocket clients.

•The Test module supports the testing of Spring components with JUnit or TestNG frameworks.
COMPONENTS OF SPRING:

• IoC
• AOP
• DI
• MVC

Inversion of Control:
It is the concept of using the dependency injection to loosely couple the java classes using the spring
containers.
The Spring container is at the core of the Spring Framework. The container gets its instructions on what
objects to instantiate, configure, and assemble by reading the configuration metadata provided. The
configuration metadata can be represented either by XML, Java annotations, or Java code. Spring
container has two types of containers to implement the IoC.

Sr.No. Container & Description


1 Spring BeanFactory Container This is the simplest container providing the basic support for DI and is defined by
the org.springframework.beans.factory.BeanFactory interface. The BeanFactory and related interfaces, such as
BeanFactoryAware, InitializingBean, DisposableBean, are still present in Spring for the purpose of backward
compatibility with a large number of third-party frameworks that integrate with Spring.
2 Spring ApplicationContext Container This container adds more enterprise-specific functionality such as the ability to
resolve textual messages from a properties file and the ability to publish application events to interested event
listeners. This container is defined by the org.springframework.context.ApplicationContext interface.
Dependency Injection:

The process of creating an object for some other class and let the
class directly using the dependency is called Dependency Injection.
It mainly has three classes involved:

Client Class: This is the dependent class and is dependent on the


Service class.

Service Class: This class provides a service to the client class.

Injector Class: This class is responsible for injecting the service


class object into the client class.
There are mainly three types of Dependency Injection:
•Constructor Injection: In this type of injection, the injector supplies dependency through the
client class constructor.
•Setter Injection / Property Injection: In this type of injection, the injector method injects the
dependency to the setter method exposed by the client.
•Interface Injection: In this type of injection, the injector uses Interface to provide dependency to
the client class. The clients must implement an interface that will expose a setter
method which accepts the dependency.
AOP(Aspect Oriented Programming):
Aspect Oriented Programming (AOP) compliments OOPs because
it provides modularity. But, the key unit of modularity here is
considered as an aspect rather than class. Here, AOP breaks the
program logic into distinct parts (called concerns). It is used to
increase modularity by cross-cutting concerns.

Spring AOP consists of 7 core concepts which are depicted in the


following diagram:
Aspect: Aspects can be a normal class configured through Spring
XML configuration. It can also be regular classes annotated using
@Aspect annotation.
Joinpoint: The joinpoint is a candidate point in the program execution where an aspect can be
plugged in. It could be a method that is being called, an exception being thrown, or even a field being
modified.

Advice: Advice are the specific actions taken for a particular joinpoint. Basically, they are the
methods that get executed when a certain joinpoint meets a matching pointcut in the application.

Pointcut: A Pointcut is an expression that is matched with join points to determine whether advice
needs to be executed or not.

Target Object: These are the objects on which advices are applied.

Proxy: It is an object that is created after applying advice to the target object. 

Weaving: Weaving is the process of linking an aspect with other application types or objects to create
an advised object.
MVC(MODEL VIEW- CONTROLLER)

It is a Java framework which is used to build web applications. It follows the Model-View-


Controller design pattern.Spring MVC provides a dignified solution to use MVC in Spring
Framework by the help of DispatcherServlet. In this case, DispatcherServlet is a class that receives
the incoming request and maps it to the right resource such as Controllers, Models, and Views.

The spring MVC contains the following components:


Model – Model contains the core data of the application. Data can either be a single object or a
group of objects.

Controller – It contains the business logic of an application. You can use @Controller annotation


to mark the class as Controller.

View – Basically, the View is used to represent the information in a particular format. Here, you
can use JSP+JSTL to create a view page.

Front Controller – In Spring Web MVC, the DispatcherServlet class works as the front


Controller.
WORKING OF SPRING MVC:

•As shown in the figure, all the incoming requests are


obstructed by the DispatcherServlet that works as the
front Controller.

•This DispatcherServlet gets an entry of handler


mapping from the XML file and forwards the request to
the Controller.

•After that, the Controller returns an object


of ModelAndView.

•Finally, the DispatcherServlet checks the entry of view


resolver in the XML file and then invokes the specified
view component.

That was all about the workflow of Spring MVC.


SPRING BEAN:

• The objects that form the backbone of your application and that are managed by the Spring IoC
container are called beans.
• Bean definition contains the information called configuration metadata.
• A bean is an object that is instantiated, assembled, and otherwise managed by a Spring IoC
container.

There are three important methods to provide configuration metadata to the Spring Container −
1. XML based configuration file.
2. Annotation-based configuration
3. Java-based configuration

• When defining a <bean> you have the option of declaring a scope for that bean.there are
generally 5 types of scope:
1. Singleton
2. Prototype
3. Request
4. Session
5. Global-session
BEAN LIFECYCLE:

• The lifecycle of bean generally contains two phases like initialization ,usable state
and destroy state.
• we simply declare the <bean> with initmethod and/or destroy-
method parameters.
• The init-method attribute specifies a method that is to be called on the bean
immediately upon instantiation.
• The destroymethod specifies a method that is called just before a bean is removed
from the container.
Interface for initialization is org.springframework.beans.factory.InitializingBean
interface.

Interface for destroy is org.springframework.beans.factory.DisposableBean interface.


BEAN POST PROCESSOR

• The BeanPostProcessor interface defines callback methods that you can implement to


provide your own instantiation logic, dependency-resolution logic, etc.

• multiple BeanPostProcessor interfaces can be controlled in the order in which these


BeanPostProcessor interfaces execute by setting the order property provided the
BeanPostProcessor implements the Ordered interface.

• An ApplicationContext automatically detects any beans that are defined with the


implementation of the BeanPostProcessor interface and registers these beans as
postprocessors, to be then called appropriately by the container upon bean creation.

You might also like