background image

Getting Started 

with Spring 3

By Josh Long

background image

Agenda

l

who am I?

l

overview of the latest and greatest in Spring 3

l

why should you care?

background image

Who am I?

 Lead Author 

 “Spring Enterprise Recipes”

 “Spring Recipes, 2nd Edition”

 Editor on Infoq.com

 Blogger on Artima.com

 JCP member

 International speaker / authority on all things Spring-y 

    (and bouncy)

background image

Who am I?

Most notably, I’m very fortunate 
and proud to be a fellow…

… employee: 

jlong@shopzilla.com

 

background image

Java 5: Generics

ApplicationContext

background image

Java 5: Generics

ApplicationContext

background image

Java 5: Generics

ApplicationContext

background image

Java 5: Generics

ApplicationContext Events

background image

Java 5: Generics

ApplicationContext Events

...

background image

Java 5: Executors

Java

l

j.u.concurrent.AbstractExecutorService

l

j.u.concurrent.DelegatedExecutorService

l

j.u.concurrent.DelegatedScheduledExecutorService

l

j.u.concurrent.FinalizableDelegatedExecutorService

background image

Java 5: Executors

Spring

o.s.core.task.support.

l

ConcurrentExecutorAdapter

l

o.s.scheduling.concurrent.

l

ConcurrentTaskScheduler

l

o.s.core.task.support.

l

ExecutorServiceAdapter

l

o.s.jca.work.glassfish.

l

GlassFishWorkManagerTaskExecutor

l

o.s.jca.work.jboss.

l

JBossWorkManagerTaskExecutor

background image

Java 5: Scheduled Methods

background image

Java 5: Scheduled Methods

...

background image

Java 5: Async Methods

background image

SpEL

l

History in Spring Batch Step Scope

l

History in Spring.NET

l

l

Andy Clement’s a rockstar

background image

SpEL: what can it do?

'Hello Shopzilla!'
'ceci n''est pas une String'
1
true

{

Literal values:

background image

SpEL: what can it do?

new String(
 'Hello Shopzilla, again!')

new com.shopzilla.Cat(
 'Felix')

{

construction

background image

SpEL: what can it do?

'felix'.toUpperCase()

T(java.lang.Math).random()

{

method invocation

background image

SpEL: what can it do?

1 > 2

T(java.lang.Math).random() > .5 ? 
   'She loves Me' : 
   'She loves me not'

{

Relational operators

background image

SpEL: what can it do?

myArray[1]

myCollection[1]

MyMap['Shopzilla']

{

collections

background image

SpEL: what can it do?

myArray.?[#this < 10] 

myMap.?[value.equals('brie')] 

{

selection

background image

SpEL: what can it do?

collectionOfCats.![name]

mapOfProducts.![value.id]

{

projection

background image

SpEL: what can it do?

systemProperties['user.home']

service.client.soTimeout 

{

references

background image

SpEL: what can it do?

background image

SpEL: what can it do?

background image

SpEL: what can it do?

background image

SpEL: what can it do?

background image

Annotations

background image

Choices, Choices...

Annotations:

Pros:

Compact, where they apply
Type safe

Cons:

Not always applicable
Not self documenting because the annotations 

are interspersed in your code

background image

Choices, Choices...

XML:

Pros:

Compact, where schema applies
Self documenting (one artifact to rule them all)

Cons:

Spring XML support isn't particularly good unless

you're using IntelliJ, Netbeans, Vi, Emacs, JEdit, 
Butterflies, JDeveloper, older builds of JBuilder...

Configuration is harder to unit test 

(and definitely a place where you should
unit test)

background image

Java Config

background image

Java Config

background image

Java Config

background image

Java Config

background image

My Code Doesn’t Compile!

 There is no more spring.jar

(use spring-core.jar, spring-context.jar, etc..) 

There is no more spring-agent.jar

(use spring-instrument.jar)

background image

Spring MVC 

background image

Spring MVC 

Pretty Annotations for General MVC Goodness

background image

Spring MVC 

JSR 303 Validation API 

(spearheaded by that other middleware 

company, whose name rhymes with “JToss”)

background image

Spring MVC : REST Remix

background image

Spring MVC 

<filter>
  <filter-name>etagFilter</filter-name>
    <filter-class>org.springframework.web.filter.ShallowEtagHeaderFilter</filter-class>
</filter>

<filter-mapping>
  <filter-name>etagFilter</filter-name>
  <servlet-name>petclinic</servlet-name>
</filter-mapping>

background image

Other Niceties

 Embedded Database Support:  

o.s.jdbc.datasource.embedded

 XPathTemplate

background image

Deprecated

Very little, actually…

Apache OJB support (awww.)

Native Toplink Support (The JPA provider’s still supported)

Spring MVC base controllers 

Junit 3 Testing support

Commons Attributes Support

WebLogic 8.1 and WebSphere 5.1 

background image

Summary

 Spring 3 is an easy upgrade

 Simplifies Component code even further

 Spring 3 is the baseline for other projects going forward: 

Spring BlazeDS 
Spring Security 
Spring Batch 
Spring Integration
Spring MVC

 

Spring 3 is an evolution, 

not a revolution – it's 99% backwards compatible


Document Outline