What is Spring?
Spring is an open source, lightweight, application framework
that is intended to help structure entire applications in a consistent manner,
pulling together best of breed single-tier frameworks in a coherent
architecture
Spring provides us below features.
- Complexity of solution
- Timeline
- Maintainability
- Familiarity with framework
- Community and Documentation
- Framework Licensing
Spring Architecture Diagram
- IoC Container
- Aspect-Oriented Programming Framework (AOP)
- Data access abstraction and JDBC simplifications
- Transaction Management
- MVC web framework
- Simplification for working with J2EE APIs such as JNDI, JTA, etc.
- Lightweight remoting, JMS support, JMX support
- Support for a comprehensive testing strategy for application developers
Inversion of Control
(IoC)
- The Hollywood Principle, “Don’t call us, we’ll call you.” IoC can be thought of in terms of what distinguishes a framework from library.
- A Library performs some work when called and returns to caller. Framework encapsulates some abstract design incorporated with behavior but to use you must incorporate you unique behavior via call backs or sub-classing.
- IoC is a principle that is used to wire an application together,how dependencies or object graphs are created
To use Spring
Dependency
Injection all you need is…
- POJO with correct constructor (or setter)
- Spring bean defined in spring-config.xml
- Access the Bean through the Spring context bean factory
POJOs
- Constructor
- Setter
- Constructor Injection
- Setter Injection
- Lookup Method Injection
Bean Factory Lookup
SomeClass instance = (SomeClass)
context.getBean(“beanName”);
Where context is an implementation of
org.springframework.beans.factory.BeanFactory
Spring Bean Lookup
Factory
The Factory Pattern: one object is responsible for creating
and maintaining the lifecycle of another object. The lifecycle of Spring Beans
(singleton) is controlled by the Bean Factory.
Spring AOP
“Aspect-Oriented Programming (AOP) complements OOP by providing
another way of thinking about program structure. While OO decomposes applications
into a hierarchy of objects, AOP decomposes programs into aspects or concerns.
This enables modularization of concerns such as transaction management that
would otherwise cut across multiple objects. (Such concerns are often termed crosscutting
concerns.)
How does Spring
enable and make use of AOP
To provide declarative
enterprise services, especially as a replacement for EJB declarative services.
The most important such service is declarative transaction management, which
builds on spring’s transaction abstraction. To allow users to implement custom
aspects, complementing their use of OOP with AOP.
No comments:
Post a Comment