Вы находитесь на странице: 1из 24

Java EE Architecture with the

Spring Framework

Peter Thomas
Peter Thomas
Satyam Computer Services Ltd.

1
Overview

Spring: quick intro

JTrac – a real-life Spring web-app

Architecture
− DI / IoC
− Spring DAO / Hibernate support
− Spring AOP / Declarative TX
− Spring MVC / Webflow
− Acegi Security Framework
− Spring Modules

Spring implications

Selected best practices
2
Spring – History

Feb 2003: SourceForge


Project founded
Nov 2002 Aug 2003: 1.0 M1 Jul 2004

Mar 2004: 1.0

3
JTrac – http://jtrac.info

JTrac: highly customizable issue tracking

4
JTrac Architecture

JSP / JSTL

Presentation Spring MVC

Spring Spring WebFlow


Security
(Acegi)
POJO POJO POJO
Spring
Context
Service (DI / IoC
Spring AOP container)

Spring TX

Spring DAO / Hibernate Support


Persistence
Hibernate 3

Database

5
Dependency Injection

JtracImpl.java

6
Dependency Injection (2)
Controllers

Service Interface

Service Implementation

DAO Interface

DAO Implementation

7
Hibernate with Spring

One liners

Template pattern

No need to deal with TX, Session etc.

8
Spring DAO – Exception Hierarchy

9
Spring AOP / Declarative TX Mgmt.

Controllers

Service Interface

“jtrac” TX Proxy

“jtracTarget” Service Implementation

DAO Interface

DAO Implementation

10
Spring AOP (contd…)
MVC Action

Spring
TX Proxy (AOP)

Service Layer
Method call DAO method

11
Spring Web Flow
Logical
View Name

State
Transitions

backend logic
call (normal
Java method)

Flow Decision

Re-usable
Flow invocation

Space yes user


submit userForm == Allocate
Handler null ?
Flow
userForm no

cancel userList
View 12
Security with Acegi

any URL request within


the “/admin/”
directory or path
can only be allowed for
“ROLE_ADMIN”
Any other request has
to be allowed only
for authenticated users

13
Spring Modules example: Lucene

14
JTrac: Spring implications

Application deployed as a WAR file

Portable: Tomcat, Jetty, JBoss or any Java EE app server

Easily unit-testable

Faster build-deploy-test cycles

Clean OO design, designed to interfaces

No EJBs

No Singletons

No Service Locator / JNDI lookup

No custom “Factory Pattern” implementation

No DTOs / VOs

No Annotations (optional)

JSTL / JSP

15
Why not RoR :)

Spring

Hibernate
− Lazy Loading

HSQLDB
− Embedded database

Jetty
− Small footprint
− Embedded app-server + web server !

Libraries
− JavaSVN, JFreeChart, Lucene, Apache POI

i18n

16
Notable in Spring 2.0

Async task execution

Portlet MVC

Use Groovy, JRuby etc. for config

MVC: Custom taglib for form controls (like
Struts)

Message driven POJOs

JPA support

Simplified XML config option

AspectJ integration

17
Agile Development with Spring + Hibernate

Spring
Delete all previous build
clean
− No need of container artifacts / database files
from file system
− JUnit support classes
Compile all code and unit
compile
− POJOs inherently easy to test tests


Hibernate Boot a fresh instance of
db-start the HSQLDB database
− Completely abstracts DB server

− HSQLDB can be used for Connect to the database


testing db-create and forward-generate the
schema from the mapping
− Unit tests can assume that DB files using Hibernate.
exists, no mocks reqd.
test Run unit-tests.

db-stop Shutdown database.

reports Generate Reports

18
DEMO

Unit + Integration Testing

19
Watij [ http://watij.com/ ]

A new class of web test automation tools
− Watir
− Web Application Testing in Ruby
− Selenium
− Watij
− Web Application Testing in Java

Focus on using a real browser, not
simulating one

Especially important when lots of Javascript
/ AJAX

20
Watij Features

Write tests in pure Java

Interactively script tests using BeanShell

Possible to drive tests using JUnit

No setup required on the Server Under Test

Support for nested tables, frames

Good “popup” and multi-window support

And also “brute-force” keystroke support…

21
Watij in conjunction with JUnit

22
DEMO

Watij

Driving functional tests with JUnit

23
Thank you

http://jtrac.info

24

Вам также может понравиться