An
Introduction to Spring Framework
What is Spring ?
Spring
is an application framework. Unlike
single-tier frameworks such as Struts or Hibernate, Spring aims to help
structure whole applications in a consistent, productive manner, pulling
together best-of-breed single-tier frameworks to create a coherent
architecture.
Why Spring ?
The
Spring Framework is an open source application framework that aims to make J2EE
development easier. We’ll look at the motivation for Spring, its goals, and how
Spring can help you develop high-quality applications quickly. Using J2EE “out of the box” is not an
attractive option.
Many J2EE APIs and services are
cumbersome to use. J2EE does a great job of standardizing low-level
infrastructure, solving such problems as how can Java code access transaction
management without dealing with the details of transactions. But J2EE does not
provide an easily usable view for application code.That is the role of an
application framework, such as Spring.
Spring enables you to enjoy the key
benefits of J2EE, while minimizing the complexity encountered by application
code. The essence of Spring is in providing enterprise services to Plain Old
Java Objects (POJOs). This is particularly valuable in a J2EE environment, but
application code delivered as POJOs is naturally reusable in a variety of
runtime environments.
Spring - Architecture
Spring could potentially be a
one-stop shop for all your enterprise applications. However, Spring is modular,
allowing you to pick and choose which modules are applicable to you, without
having to bring in the rest. The following section provides details about all
the modules available in Spring Framework. The Spring Framework provides about
20 modules which can be used based on an application requirement
Enter
Spring
Spring is
both the most popular and most ambitious of the lightweight frameworks. It is
the only one to address all architectural tiers of a typical J2EE application,
and the only one to offer a comprehensive range of services, as well as a
lightweight container. We’ll look at Spring’s modules in more detail later, but
the following are the key Spring modules :
·
Inversion of Control container: The core “container” Spring provides,
enabling sophisticated configuration management for POJOs. The Spring IoC
container can manage fine or coarse grained POJOs (object granularity is a
matter for developers, not the framework), and work with other parts of Spring
to offer services as well as configuration management. This is also called as Dependency
Injection
Spring
supports several types of Dependency Injection, those are :
o
Setter Injection: The injection of dependencies via JavaBean
setter methods. Often, but not necessarily, each setter has a corresponding getter
method, in which case the property is set to be writable as well as readable.
o
Constructor Injection: The injection of dependencies via
constructor arguments.
o
Method Injection: A more rarely used form of Dependency
Injection in which the container is responsible for implementing methods at
runtime. For example, an object might define a protected abstract method, and
the container might implement it at runtime to return an object resulting from
a container lookup. The aim of Method Injection is, again, to avoid
dependencies on the container API.
·
Aspect-Oriented Programming (AOP) framework: AOP enables behavior that would otherwise be
scattered through different methods to be modularized in a single place. Spring
uses AOP under the hood to deliver important out-of-the-box services such as
declarative transaction management. Spring AOP can also be used to implement
custom code that would otherwise be scattered between application classes.
·
MVC web framework: Spring provides a request-based MVC web
framework. Its use of shared instances of multithreaded “controllers” is
similar to the approach of Struts, but Spring’s web framework is more flexible,
and integrates seamlessly with the Spring IoC container. All other Spring
features can also be used with other web frameworks such as Struts or JSF.
·
Lightweight remoting: Spring provides support for POJO-based
remoting over a range of protocols, including RMI, IIOP and other web services
protocols.
·
Support for a comprehensive testing strategy
for application developers: Spring not
only helps to facilitate good design, allowing effective unit testing, but
provides a comprehensive solution for integration testing outside an
application server.
Conclusion
Spring is a framework that helps you
to "wire" different components together. It is most useful in cases
where you have a lot of components and you might decide to combine them in
different ways, or wish to make it easy to swap out one component for another
depending on different settings or environments.
- Spring is
light weight and It minimally invasive development with POJO.
- Spring
achieves the loose coupling through dependency injection and interface based programming.
- Declarative
programming through aspects and common conventions.
- Boilerplate reduction through aspects and templates.
Comments
Post a Comment