Spring Framework
Spring uses various new techniques such as Aspect-Oriented Programming (
AOP
), Plain Old Java Object (POJO
), and dependency injection (DI
), to develop enterprise applications, therebyremoving the complexities
involved while developing enterprise applications using EJB
Spring mainly focuses on
providing
variousways
to help youmanage your business objects
The Spring framework can be considered as
a collection of sub-frameworks
, also called layers, such asSpring AOP
, Spring Object-Relational Mapping (Spring ORM
).Spring Web Flow
, andSpring Web MVC
Spring Framework Features
- Lightweight
The Spring Framework is very lightweight with respect to its size and functionality. It is due to its
POJO implementation
which doesn’t force to inherit any class or implement any interfaces. - Aspect Oriented Programming(AOP)
It is an important part of Spring Framework.
Aspect Oriented Programming
is used forseparating cross-cutting concerns
(for example logging, security etc.) from the business logic of the application. - Transaction Management
This framework provides Java Transaction API (
JTA
) forglobal transactions
managed by an application server and local transactions managed by using the JDBC, Hibernate, Java Data Objects (JDO), or other data access APIs. - IoC container
Refers to the
core container
that uses theDI or IoC
pattern to implicitly provide anobject reference
in a classduring runtime
, help manage thelifecycle
andconfigurations
of application objects. - Dependency Injection
Dependency Injection is a feature of Spring Framework allows you to develop loosely coupled applications. Therefore, the unit testing of these loosely coupled applications becomes easier.
//without DI public class TextEditor { private SpellChecker spellChecker; public TextEditor() { spellChecker = new SpellChecker(); } } //with DI public class TextEditor { private SpellChecker spellChecker; public TextEditor(SpellChecker spellChecker) { this.spellChecker = spellChecker; } }
Spring Framework Architecture
- Spring Core Module
Provides the
IoC container
, there are two types of implementations of the Spring container, namely,bean factory
andapplication context
. The Bean factory container allows you todecouple the configuration and specification of dependencies
from program logic. In the Spring framework, the Bean factory acts as acentral IoC container
that is responsible forinstantiating application objects
. It alsoconfigures and assembles
thedependencies
between these objects. - Spring AOP Module
Spring AOP module allows you to implement
concerns or aspects
in a Spring application in Spring AOP, the aspects are the regularSpring beans
orregular classes
annotated with@Aspect
annotation. - Spring ORM Module
Used for
accessing data
from databases in an application. It provides APIs for manipulating databases withDAO, JDO, Hibernate, and iBatis
. - Spring Web MVC Module
It implements the
MVC architecture
for creating Web applications. - Spring Web Flow Module
The Spring Web Flow helps in
defining XML file
orJava Class
thatmanages the workflow
betweendifferent pages
of a Web application. - Spring Web DAO Module
Provides
DAO support
by using data access technologies such as JDBC, Hibernate, or JDO. This module introduces aJDBC abstraction layer
by eliminating the need for providing tedious JDBC coding. - Spring Application Context Module
Based on the Core module, this module derives its feature from the
org.springframework.beans
package and also supports functionalities such asinternationalization, validation, event propagation, and resource loading
. The Application context implementsMessageSource interface
and provides themessaging functionality
to an application.
Spring MVC
In Spring MVC, when a
Request
is generated from the browser, it first goes to theDispatcherServlet
class (Front Controller), which dispatches the request to aController
(SimpleFormController class or AbstractWizardformController class) using a set ofHandler Mappings
. The controller extracts and processes the information embedded in a request and sends the result to the DispatcherServlet class in the form of the model object. Finally, the DispatcherServlet class usesViewResolver
classes to send the results to aView
, which displays these results to the users.