Spring Introduction
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 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.
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 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 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 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
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 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:
• 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 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 Java Messaging Service JMS module contains features for producing and consuming
messages.
•The Aspects module provides integration with AspectJ, which is again a powerful and mature AOP
framework.
•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.
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:
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.
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)
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.
• 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.