Sie sind auf Seite 1von 100

Spring

Spring is great framework for development of

Enterprise grade applications. Spring is a light-weight


framework for the development of enterprise-ready
applications. Spring can be used to configure
declarative transaction management, remote access to
your logic using RMI or web services, mailing
facilities and various options in persisting your data
to a database. Spring framework can be used in
modular fashion, it allows to use in parts and leave
the other components which is not required by the
application.

Features of Spring Framework:


Transaction

Management: Spring framework provides a generic abstraction layer


for transaction management. This allowing the developer to add the pluggable
transaction managers, and making it easy to demarcate transactions without dealing
with low-level issues. Spring's transaction support is not tied to J2EE environments
and it can be also used in container less environments.

JDBC

Exception Handling: The JDBC abstraction layer of the Spring offers a


meaningful exception hierarchy, which simplifies the error handling strategy

Integration

with Hibernate, JDO, and iBATIS: Spring provides best Integration


services with Hibernate, JDO and iBATIS.
AOP Framework: Spring is best AOP framework
MVC Framework: Spring comes with MVC web application framework, built on
core Spring functionality. This framework is highly configurable via strategy
interfaces, and accommodates multiple view technologies like JSP, Velocity, Tiles,
iText, and POI. But other frameworks can be easily used instead of Spring MVC
Framework..

Spring Architecture
Spring is well-organized architecture consisting

of seven modules. Modules in the Spring framework are:

Spring

AOP
One of the key components of Spring is the AOP framework. AOP is used in Spring:

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

Spring

ORM
The ORM package is related to the database access. It provides integration layers for popular object-relational mapping APIs,
including JDO, Hibernate and iBatis.

Spring

Web
The Spring Web module is part of Spring?s web application development stack, which includes Spring MVC.

Spring

DAO
The DAO (Data Access Object) support in Spring is primarily for standardizing the data access work using the technologies like
JDBC, Hibernate or JDO.

Spring

Context
This package builds on the beans package to add support for message sources and for the Observer design pattern, and the ability
for application objects to obtain resources using a consistent API.

Spring

Web MVC
This is the Module which provides the MVC implementations for the web applications.

Spring

Core
The Core package is the most import component of the Spring Framework.
This component provides the Dependency Injection features. The BeanFactory provides a factory pattern which separates the
dependencies like initialization, creation and access of the objects from your actual program logic.

Software Development Challenges


Solutions are complex
Requirements are constantly in flux
Software architecture must be flexible
Software components must be verifiable

Spring Approach
Products based on simplicity
Maintainable systems
Framework-independent software
Portable components
Testable components
Reliable and predictable systems

Pure Java
Founded on POJO-based development
Ordinary Java classes that follow no special APIs
Non-invasive for pre-existing POJOs
Rewards framework-independent business
logic
Encourages new software to be written as
POJOs
Results in highly portable, reusable, and
verifiable software

More With Less Custom Code

Expand capabilities with less code


Extensive and tested service abstractions
Email
JMS
JMX
JSF
JDBC
etc
Replaces generic corporate libraries
Mitigates custom integration activities
Consistency eases integration because
spring platform is easy to use

Modular
Helps only where needed
Modularity allows only relevant components to be
introduced into the application
For instance choose one:
Spring BeanFactory
Spring JMX
Spring JDBC
Framework can be interfaced in deep or shallow layers.
Interfaces are consistent at each layer
Turn-key solution
Spring components can be integrated quickly, with
minimal effort and predictable results
Interfaces are clear and consisten

Widely Available
Spring is integrated into numerous
frameworks
Broad adoption possible because the
container is portable and lightweight
The container itself is designed as a POJO
Integration without third-party support
Performance overhead is rarely a
consideration

Spring Hello World


Code a plain Java class model
Use the interface pattern by coding a HelloWorld
interface and a
HelloWorldImpl implementation
Configure the Spring IoC container
Instantiate the Spring IoC container
Acquire the object from the Spring IoC
container
The client must only have knowledge of the interface,
HelloWorld

Background:
POJO Development

Runtime Environment

Manual (Non-Spring)
Dependency Injection

Manual (Non-Spring)
Inversion of Control

The Core Spring Module:


Defining Beans
and Dependency Injection

Agenda
Setting bean properties
Supplying constructor arguments
Using factory methods
Dependency injection
Supplying other beans as properties or
constructor args
Bean scopes

Simple Properties

Constructor Arguments

Factory Methods

Dependency Injection
Supplying Other Beans
as Properties or Constructor Args

Bean Scopes

Das könnte Ihnen auch gefallen