0% found this document useful (0 votes)
910 views

Spring Framework

The document discusses the Spring Framework, which aims to simplify J2EE development. It provides an inversion of control container and aspects for transactions, data access, MVC, and more. Spring reduces complexity by promoting loose coupling, interfaces over classes, and easy configuration. It also emphasizes testability. The document outlines Spring's features and provides examples of its use for controllers, transactions, data access with Hibernate/JDBC, and more.

Uploaded by

Raja Sekhar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
910 views

Spring Framework

The document discusses the Spring Framework, which aims to simplify J2EE development. It provides an inversion of control container and aspects for transactions, data access, MVC, and more. Spring reduces complexity by promoting loose coupling, interfaces over classes, and easy configuration. It also emphasizes testability. The document outlines Spring's features and provides examples of its use for controllers, transactions, data access with Hibernate/JDBC, and more.

Uploaded by

Raja Sekhar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

The Spring Framework

Simplifying J2EE

!ww.springlive.co"

!ww.raibledesigns.co"

Who is Matt Raible?


Developing websites since 1994 - Developing
J2EE webapps since 1999
Committer on several open source projects:
Roller Weblogger, XDoclet, Struts Menu,
Display Tag, AppFuse
J2EE 5.0 and JSF 1.2 Expert Group Member
Author: Spring Live (SourceBeat) and
contributor to Pro JSP (Apress)
!ww.springlive.co"

!ww.raibledesigns.co"

Spring Mission Statement


J2EE should be easier to use.
Its best to program to interfaces, rather than
classes. Spring reduces the complexity of
using interfaces to zero.
JavaBeans oer a great way of conguring
applications.
OO Design is more important than any
implementation technology, such as J2EE.
!ww.springlive.co"

!ww.raibledesigns.co"

Spring Mission Statement


Checked exceptions are overused in Java. A
framework shouldnt force you to catch
exception youre unlikely to recover from.
Testability is essential, and a framework such
as Spring should help make your code easier
to test.

!ww.springlive.co"

!ww.raibledesigns.co"

What is it?
A J2EE Framework designed to make building
applications easier.
Provides a means to manage your business
objects and their dependencies.
Inversion of Control allows classes to be
loosely coupled and dependencies written in
XML.

!ww.springlive.co"

!ww.raibledesigns.co"

What is it?

!ww.springlive.co"

!ww.raibledesigns.co"

Sample Architecture

!ww.springlive.co"

!ww.raibledesigns.co"

The BeanFactory

Example: DAO and DataSource


DAO has a setter or a constructor argument
for the DataSource
DataSource is congured as a dependency of
the DAO
Makes it easy to swap out implementations
Tests can verify operations succeed on the
interface
!ww.springlive.co"

!ww.raibledesigns.co"

Spring MVC
Front-Controller Servlet: DispatcherServlet
Controllers loaded as beans from servlets
XML context les
ContextLoaderListener loads other XML
context les
Many dierent Controller options:
Controller, SimpleFormController, Wizard
!ww.springlive.co"

!ww.raibledesigns.co"

Examples: Controllers
The Controller interface is generally used to
display data, not for forms.
SimpleFormController easiest for forms.
JSP Tags, Velocity, FreeMarker, PDF, Excel
Validation: Commons Validator or Validation
classes

!ww.springlive.co"

!ww.raibledesigns.co"

Supports MVC Frameworks


ContextLoaderListener loads beans into
ServletContext
Struts has ContextLoaderPlugin and
ActionSupport classes
WebWork has SpringObjectFactory
Tapestry - override BaseEngine and stu the
context into the Global
JSF - VariableDelegateResolver
!ww.springlive.co"

!ww.raibledesigns.co"

MVC Tips
JSP 2.0 Tag les in JIRA - for syntax
simplication
Use SiteMesh - simple yet powerful
AppFuse and Equinox have good integration
examples

!ww.springlive.co"

!ww.raibledesigns.co"

Data Access
Spring JDBC Framework
No exceptions to catch or resources to
close
Base DAO and Template classes for many
frameworks:
Hibernate, iBATIS, OJB, JDO - even
TopLink
Hibernate 3 support in JIRA
!ww.springlive.co"

!ww.raibledesigns.co"

DataAccessException

!ww.springlive.co"

!ww.raibledesigns.co"

Data Access Examples


UserDAOTest
Hibernate
iBATIS
Spring JDBC
JDO

!ww.springlive.co"

!ww.raibledesigns.co"

Transactions
Much easier to use than UserTransaction in
J2EE
CMT-like capabilities with XML and
transparent AOP
Supports Commons Attributes and JDK 5
Annotations
Pluggable Transaction Managers, including
JTA
!ww.springlive.co"

!ww.raibledesigns.co"

Testing Spring Applications


Easy to mock dependencies with EasyMock
and jMock
Load context in tests and bind dependencies
as you would in production
TIP: Use a static block or Spring classes in
Spring Mock. In the org.springframework.test
package.

!ww.springlive.co"

!ww.raibledesigns.co"

AOP
AOP - Reduces duplication among classes
Interceptors make it easy to add before,
around and after method advice
Useful for caching, logging and security
EHCache, Performance/Tracing
interceptors, Acegi for Security

!ww.springlive.co"

!ww.raibledesigns.co"

App Server Support


Spring should run on any app server.
Hooks into many app servers Transaction
Manager.
Survey: which app servers are you running it
on?

!ww.springlive.co"

!ww.raibledesigns.co"

Tools

Spring IDE Plugin For Eclipse


BeanDoc
Screenshots

!ww.springlive.co"

!ww.raibledesigns.co"

Spring vs. J2EE


Its not really a comparison, Spring builds o
J2EE and merely makes the APIs easier
Its still using many of J2EEs and Javas
underlying infrastructure
EJB vs. Spring Managed POJOs
Opinions and Hesitations?

!ww.springlive.co"

!ww.raibledesigns.co"

Questions
Practical applications of AOP?
Multithreading with singleton beans - is it
safe?
Tips and Tricks?
What are the Gotchas?

!ww.springlive.co"

!ww.raibledesigns.co"

Questions, cont.
What environment is the best match for
Spring? Where will it not perform well?
Maintaining inter-class dependencies - tools?
Is Spring a replacement for Struts?
Can I use Spring with EJBs and Hibernate for
CMT?

!ww.springlive.co"

!ww.raibledesigns.co"

Resources
www.springframework.org and
forum.springframework.org
Interface21 oers commerical support at
www.springframework.com
Spring Live, Spring in Action and Professional
Spring Development
AppFuse (appfuse.dev.java.net) and Equinox
(equinox.dev.java.net)
!ww.springlive.co"

!ww.raibledesigns.co"

This Presentation
http://equinox.dev.java.net/SpringFramework.pdf

!ww.springlive.co"

!ww.raibledesigns.co"

You might also like