Upload
dadapeer467
View
228
Download
0
Embed Size (px)
Citation preview
8/8/2019 Spring Framework Intro
1/26
An Introduction to the Spring Framework
8/8/2019 Spring Framework Intro
2/26
What is the Spring Framework?
Spring is a Lightweight Application
Framework Where Struts, WebWork and others can be
considered Web frameworks, Spring
addresses all tiers ofan application
Spring provides the plumbing so that you
dont have to!
8/8/2019 Spring Framework Intro
3/26
Spring Framework History
Started 2002/2003 by Rod Johnsonand Juergen Holler
Started as a framework developedaround Rod Johnsons book ExpertOne-on-One J2EE Design andDevelopment
Spring 1.0 Released March 2004 2004/2005 Spring is emerging as a
leading full-stack Java/J2EEapplication framework
8/8/2019 Spring Framework Intro
4/26
Spring == J2EE Application Server?
Spring is NOT a J2EE application server
Spring can integrate nicely with J2EEapplication servers (or any Java
environment)
Spring can, in many cases, elegantly replace
services traditionally provided by J2EE
application servers
8/8/2019 Spring Framework Intro
5/26
Lessons Learned from Struts
Before Struts, everyone wrote their own front
controllers (orYIKES! put their controller logic in JSP) After Struts, the custom front controllers could be
thrown out
Developers focus on solving business problems
Productivity Gain!
But with Struts (and most of the other web
frameworks) you still have to write your own
business delegates or service layers
8/8/2019 Spring Framework Intro
6/26
Spring Can Help!
Spring brings a consistent structure to your entireapplication
Spring provides a consistent way to glue your wholeapplication together
Spring provides elegant integration points withstandard and defacto-standard interfaces: Hibernate,JDO, TopLink, EJB, RMI, JNDI, JMS, Web Services,
Struts, etc. Just as Struts did on the web tier, we can realize
huge productivity gains by not having to write thecommon integration points across your application
8/8/2019 Spring Framework Intro
7/26
Spring Framework Mission Statement(continued)
The authors of Spring aim that:
Spring should be a pleasure to use Your application code should not depend on Spring
APIs
Spring should not compete with good existing
solutions, but shouldfoster integration. (Forexample, JDO and Hibernate are great O/R mapping
solutions. We don't need to develop another one.)
8/8/2019 Spring Framework Intro
8/26
Spring Overview
from springframework.org
Note: Spring distribution comes as one big jarfile and alternatively as a series o
fsmallerjars broken out along the above lines (so you can include only what you need)
8/8/2019 Spring Framework Intro
9/26
But really, what ISSpring?
At its core, Spring provides:
An Inversion ofControl Container
Also known as Dependency Injection (Fowlers term)
An AOP Framework
Spring provides a proxy-based AOP framework
You can alternatively integrate with AspectJ or AspectWerkz
A Service Abstraction Layer
Consistent integration with various standard and 3rd party APIs
These together enable you to write powerful, scalableapplications using POJOs.
8/8/2019 Spring Framework Intro
10/26
Seriously though, what ISSpring?
Spring at its core, is a framework forwiring up your entire application
BeanFactories are the heart ofSpring
8/8/2019 Spring Framework Intro
11/26
BeanFactories
A BeanFactory is typically configured in an
XML file with the root element: The XML contains one or more
elements
id (or name) attribute to identify the bean
class attribute to specify the fully qualified class
8/8/2019 Spring Framework Intro
12/26
BeanFactories
By default, beans are treated as singletons
Can also be prototypesHere is an example:
The beans IDThe beans fully-
qualified classname
Maps to a setPoolSize() call
8/8/2019 Spring Framework Intro
13/26
Property Values forBeanFactories
Strings and Numbers
Arrays and Collections
42
Jim
Basket Weaving
Break Dancing
8/8/2019 Spring Framework Intro
14/26
Property Values forBeanFactories(continued)
The real magic comes in when you can set
a property on a bean that refers to anotherbean in the configuration:
This is the basic concept
of Inversion of Control
calls setWidgetDAO(myWidgetDAO)
where myWidgetDAO is another bean
defined in the configuration
8/8/2019 Spring Framework Intro
15/26
Dependency Injection
(Inversion of Control)
Complicated sounding terms for a fairly
simple concept The Hollywood Principle: Dont call
me, Ill call you
Dependencies used from within a beanarent asked for outwardly, but are
injected into the bean by the container
8/8/2019 Spring Framework Intro
16/26
Dependency Injection
(Inversion of Control)
Eliminates lookup code from within your
application Allows for pluggablity and hot swapping
Promotes good OO design
Enables reuse ofexisting code
Makes your application extremely testable
8/8/2019 Spring Framework Intro
17/26
A Very Special BeanFactory:
the ApplicationContext
An ApplicationContext is a BeanFactory,
but adds framework features such as: i18n messages
Event notifications
This is what you will probably most often use
in your Spring applications
8/8/2019 Spring Framework Intro
18/26
Service Abstraction Layers
Spring provides abstraction for:
Transaction Management JTA, JDBC, others
Data Access JDBC, Hibernate, JDO, TopLink, iBatis
Email Remoting
EJB, Web Services, RMI, Hessian/Burlap
8/8/2019 Spring Framework Intro
19/26
Service Abstraction Layers
Benefits:
No implicit contracts with JNDI, etc. Insulates you from the underlying APIs
Greater reusability
Spring abstractions always consist of interfaces
This makes testing simpler
For data access, Spring uses a generic transactioninfrastructure and DAO exception hierarchy that iscommon across all supported platforms
8/8/2019 Spring Framework Intro
20/26
Spring on the Web Tier
Spring integrates nicely with Struts,
WebWork, JSF, Tapestry, Velocity and otherweb frameworks
Spring also provides its own web framework,
Spring Web MVC
8/8/2019 Spring Framework Intro
21/26
Spring on the Web Tier Spring MVC
The Spring MVC Framework offers a simple
interface based infrastructure for handingweb MVC architectures
Spring MVC components are treated as first-
class Spring beans
Other Spring beans can easily be injected intoSpring MVC components
Spring MVC components are easy to test
8/8/2019 Spring Framework Intro
22/26
On to the examples
( See http://www.zabada.com/technology/Wiki.jsp?page=SpringRecipes )
8/8/2019 Spring Framework Intro
23/26
Spring Related Tools and Add-Ons
ACEGI Security - comprehensive security services for the SpringFramework
Spring IDE - graphical user interface for the configuration files used bythe Spring Framework
Spring BeanDoc - tool that facilitates documentation and graphing ofSpring bean factories and application context files
XDoclet Spring Tags - support for generating Spring XML config filesfrom annotations in Java classes (you could also use JDK1.5annotations to achieve this)
SpringW
eb Flow -for web applications with demanding page
flowrequirements
AppFuse Not really a tool or add-on, but AppFuse is Matt Raible'sproject to jumpstart your Java web projects. It uses Spring at it's coreand studying it is a great way to learn about Spring.
Spring Framework .NET Spring Clone for the Dark Side
8/8/2019 Spring Framework Intro
24/26
Spring Framework / Spring Related
References
The Official Spring Reference Manual
http://www.springframework.org/docs/reference/Introduction to Spring by Rod Johnson
http://www.theserverside.com/articles/article.tss?l=SpringFramework
Spring in Action by Craig Walls and Ryan Breidenbach
Pro Spring by Rob Harrop and Jan Machacek
J2EEWithout EJB by Rod Johnson and Juergen Holler
Expert One-on-One J2EE Design and Development by Rod JohnsonSpring Developers Notebook by Bruce Tate and Justin Gehtland
Better, Faster, Lighter Java by Bruce Tate and Justin Gehtland
Spring Live by Matt Raible
Professional Java Development with the Spring Framework
by many of the core Spring developers: Coming in July 2005
8/8/2019 Spring Framework Intro
25/26
Wrap Up
Questions/Comments?
Feedback is appreciated!
Email me: [email protected]
Were Hiring For A Few Positions
Senior Java Developer
Mid-level Java Developer
Spring/Hibernate and other relevant Java technologies
Let me know ifyoure interested: [email protected]
8/8/2019 Spring Framework Intro
26/26
Credits
Thanks to the Spring Framework Team. Sees
pringframew
ork.org Much of the content in this presentation was
inspired by presentations by Rod Johnson
and Craig Walls