Spring Framework 2'5: New Features - PowerPoint PPT Presentation

1 / 67
About This Presentation
Title:

Spring Framework 2'5: New Features

Description:

Learn about new platform support for Java EE 5, Java 6, and OSGi. ... a versioned deployment unit (i.e., a JAR file with special manifest headers in ... – PowerPoint PPT presentation

Number of Views:706
Avg rating:3.0/5.0
Slides: 68
Provided by: dub71
Category:

less

Transcript and Presenter's Notes

Title: Spring Framework 2'5: New Features


1
Spring Framework 2.5New Features Enhancements
  • Sam Brannen
  • Senior Software Engineer
  • Interface21
  • http//www.interface21.com

2
Whats new in Spring 2.5?
New features and enhancements in release 2.5 of
the Spring Framework
  • Learn about new platform support for Java EE 5,
    Java 6, and OSGi.
  • Gain insight into new configuration options for
    your applications via annotations and XML
    namespaces.
  • Simplify MVC applications with annotation-driven
    controllers.
  • See the new TestContext framework in action.

3
Agenda Part 1 Platforms
  • Java 6 Support
  • Java EE 5 Support
  • WebSphere Integration
  • Spring OSGi

4
Agenda Part 2 Configuration
  • Support for Configuration Annotations
  • context Configuration Namespace
  • Enhanced AspectJ Support
  • jms Configuration Namespace
  • Annotation-driven Web MVC Controllers

5
Agenda Part 3 TestContext Framework
  • Introduction
  • Key Abstractions
  • Examples

6
Agenda Part 1 Platforms
  • Java 6 Support
  • Java EE 5 Support
  • WebSphere Integration
  • Spring OSGi

7
Spring 2.5 Embraces New Platforms
  • Java 6 (JDK 1.6)
  • Spring 2.5 is the first major application
    framework to explicitly support JDK 1.6
  • Java EE 5
  • Spring 2.5 is explicitly designed for seamless
    use in a Java EE 5 environment
  • OSGi Support
  • Spring is the first mainstream application
    framework that explicitly targets the OSGi
    platform
  • Spring Dynamic Modules for OSGi Service Platforms

8
Java 6 (JDK 1.6) Support
  • Spring 2.5 adds support for JDK 1.6
  • Remains backwards compatible with JDK 1.5 as well
    as JDK 1.4
  • No longer supports JDK 1.3 (EOL by Sun)
  • Support for new APIs in JDK 1.6
  • JDBC 4.0
  • Native connections LOB handling
  • JMX MXBeans
  • Exported via Springs MBeanExporter
  • JDK ServiceLoader API

9
Agenda Part 1 Platforms
  • Java 6 Support
  • Java EE 5 Support
  • WebSphere Integration
  • Spring OSGi

10
Java EE 5 Support
  • Spring 2.5 explicitly supports Java EE 5
  • Remaining backwards compatible with J2EE 1.4 as
    well as J2EE 1.3
  • e.g., BEA WebLogic 8.1 or higher
  • e.g., IBM WebSphere 5.1 or higher
  • Support for Servlet 2.5, JSP 2.1, JSF 1.2
  • Support for unified expression language (EL)
  • Consistent use of JSR 250 annotations
  • Support for JTA 1.1 JavaMail 1.4
  • Also available for stand-alone usage

11
EJB 3.0 and JPA
  • Access to EJB 3.0 Session Beans
  • Effectively just fancy JNDI lookups
  • Standard ltjeejndi-lookup gt is sufficient
  • Support for the Java Persistence API (a.k.a., JPA
    / EJB 3.0 Persistence)
  • Available since Spring 2.0
  • Embedded JPA provider
  • Local EntityManagerFactory
  • Or provided by the Java EE container
  • EntityManagerFactory obtained via JNDI

12
Available Java EE 5 Servers (Q2 07)
  • Full Java EE 5 Servers
  • Suns GlassFish
  • BEA WebLogic 10
  • JBoss AS 5 beta
  • Servers with partial Java EE 5 Support
  • Oracle OC4J 10.1.3
  • JBoss AS 4.2
  • Servlet 2.5 Containers
  • Apache Tomcat 6
  • Jetty 6

13
Mainstream J2EE Platforms (06-07)
  • BEA WebLogic 8.1, 9.0
  • IBM WebSphere 5.1, 6.0, 6.1
  • JBoss 3.2, 4.0
  • Apache Tomcat 5.0, 5.5
  • Spring will continue supporting J2EE 1.3/1.4 as
    well as JDK 1.4 for the entire 2.x release branch
  • Spring 3.0, however, will be based on Java 5

14
J2EE 1.4 Deploying as RAR File
  • Spring 2.5 supports deployment of a Spring
    ApplicationContext as a RAR file
  • Package your classes and libraries into a J2EE
    1.4 (JCA 1.5) RAR file
  • Add a META-INF/ra.xml file that references a
    Spring applicationContext.xml file
  • Primarily intended for non-web deployment units
    that are entirely driven by incoming messages,
    scheduled jobs, etc.
  • Can access application server functionality such
    as the JTA TransactionManager or JMX MBeanServer

15
Agenda Part 1 Platforms
  • Java 6 Support
  • Java EE 5 Support
  • WebSphere Integration
  • Spring OSGi

16
J2EE 1.4 WebSphere Integration
  • Support for WebSphere-specific transaction
    management API
  • Including transaction suspension
  • Avoiding use of the raw JTA TransactionManager on
    WebSphere
  • On WebSphere 6.0.x and 6.1.x
  • Officially support by IBM!
  • WebSphereUowTransactionManager
  • Straightforward replacement for a standard Spring
    JtaTransactionManager

17
Agenda Part 1 Platforms
  • Java 6 Support
  • Java EE 5 Support
  • WebSphere Integration
  • Spring OSGi

18
Introducing OSGi
  • Open Services Gateway initiative
  • Backed by the OSGi Alliance, formed in 1999
  • http//www.osgi.org
  • Dynamic module system
  • Central notion of a bundle
  • A bundle is a versioned deployment unit (i.e., a
    JAR file with special manifest headers in
    META-INF/MANIFEST.MF)
  • Can specify dependencies on explicit versions of
    other bundles
  • Bundles can be dynamically installed, started,
    stopped, updated, and uninstalled
  • Enables hot redeployment at runtime!
  • Bundles can publish and consume services
  • OSGi Service Registry

19
Spring OSGi
  • Spring in an OSGi environment?
  • A natural match the simplicity and power of
    Spring with the dynamic module system of OSGi
  • Spring manages the internal structure of each
    bundle
  • One ApplicationContext per bundle
  • Springs fine-grained component model
  • General Spring middleware services
  • OSGi manages the overall collection of bundles
    and services at runtime
  • Check out the Spring Dynamic Modules for OSGi
    Service Platforms sister project!

20
Spring on OSGi vs. Spring on Java EE
  • Similar programming models
  • Services implemented as Spring managed components
  • No direct dependencies on the runtime
    environment just Spring JDK
  • Different deployment environments
  • OSGi bundle JARs, service registry
  • Java EE WAR / EAR files, JNDI environment
  • OSGi and Java EE are alternative runtimes
  • Hard to mix essentially an either/or choice
  • Spring as the common ground!

21
Agenda Part 2 Configuration
  • Support for Configuration Annotations
  • context Configuration Namespace
  • Enhanced AspectJ Support
  • jms Configuration Namespace
  • Annotation-driven Web MVC Controllers

22
Spring 2.5 embraces annotations
  • JSR-250 Common Annotations
  • Included in JDK 1.6 and Java EE 5
  • Available as a separate JAR for JDK 1.5
  • Spring Autowiring Annotations
  • Annotation-driven autowiring by type
  • Reduces XML bean configuration to a minimum
  • Autodetection of Annotated Components
  • Classpath scanning for components
  • No XML configuration necessary at all!

23
JSR-250 Common Annotations
  • Spring 2.5 supports JSR-250 Common Annotations
    for Spring-managed components
  • _at_PostConstruct and _at_PreDestroy for component
    lifecycle
  • Equivalent to init and destroy methods
  • _at_Resource for annotation-driven injection of
    named components
  • Applicable on fields as well as setter methods
  • Can be configured to retrieve components via JNDI
  • Same annotations as supported by Servlet 2.5 and
    JSF 1.2 managed beans
  • Seamless, consistent component model

24
JSR-250 Annotation Example
  • public class MyService implements
    MyServiceInterface
  • _at_Resource
  • private DataSource dataSource
  • _at_PostConstruct
  • public void initialize()
  • public class MyService implements
    MyServiceInterface
  • private DataSource dataSource
  • _at_Resource(namemyDataSource)
  • public void setDataSource(DataSource
    dataSource)
  • _at_PreDestroy
  • public void shutdown()
  • // No specific configuration is necessary!

25
Autowiring Annotation
  • New _at_Autowired Annotation
  • For annotation-driven autowiring by type
  • Applicable on fields, config methods, and
    constructors
  • AutowiredAnnotationBeanPostProcessor
  • Motivation
  • Autowiring by name is often too simplistic
  • Autowiring by type is often too expensive
  • _at_Autowired hits a sweet spot in the middle
  • Specific autowiring by type, driven by explicit
    annotations!

26
Autowiring Annotation Example
  • public class MyService implements
    MyServiceInterface
  • _at_Autowired
  • private DataSource dataSource
  • _at_Autowired
  • public void injectServices(ServiceA a, ServiceB
    b)
  • public class MyService implements
    MyServiceInterface
  • _at_Autowired
  • public MyService(DataSource dataSource,
    ServiceA a)
  • _at_PreDestroy
  • public void shutdown()
  • // No specific configuration necessary driven by
    annotations
  • ltbean idmyService classmypackage.MyService
    /gt

27
_at_Qualifier Annotation
  • New _at_Qualifier Annotation
  • For annotation-driven autowiring by type with
    hints
  • Used on a field or parameter as a qualifier for
    candidate beans
  • May also be used to annotate other custom
    annotations that can then in turn be used as
    qualifiers
  • Motivation
  • Since autowiring by type may lead to multiple
    candidates, it is often necessary to have more
    control over the selection process
  • _at_Qualifier allows you to select a specific
    candidate
  • by name, or
  • with a custom qualifier annotation

28
_at_Qualifier Example by name
public class JdbcOrderRepositoryImpl implements
OrderRepository // autowire DataSources by
type with qualifying names _at_Autowired public
void init( _at_Qualifier("myDataSource")
DataSource orderDataSource,
_at_Qualifier("otherDataSource") DataSource
inventoryDataSource, MyHelper
autowiredByType) // ltbean
idmyDataSource classexample.DataSourcegt
lt!- connection properties for Order DataSource
--gt lt/beangt ltbean idotherDataSource
classexample.DataSourcegt lt!- connection
properties for Inventory DataSource --gt lt/beangt
29
_at_Qualifier Example custom annotation
_at_Target(ElementType.FIELD, ElementType.PARAMETER
) _at_Retention(RetentionPolicy.RUNTIME) _at_Qualifier p
ublic _at_interface Genre String
value() public class MovieRecommender
_at_Autowired _at_Genre("Action") private
MovieCatalog actionCatalog private
MovieCatalog comedyCatalog _at_Autowired
public void setComedyCatalog(
_at_Genre("Comedy") MovieCatalog comedyCatalog)
this.comedyCatalog comedyCatalog
// ...
30
_at_Qualifier Example custom annotation
ltcontextannotation-config/gt ltbean
class"example.SimpleMovieCatalog"gt ltqualifier
type"Genre" value"Action"/gt lt!-- inject any
dependencies required by this bean
--gt lt/beangt ltbean class"example.SimpleMovieCatal
og"gt ltqualifier type"example.Genre"
value"Comedy"/gt lt!-- inject any dependencies
required by this bean --gt lt/beangt ltbean
id"movieRecommender" class"example.MovieRecommen
der"/gt
31
Agenda Part 2 Configuration
  • Support for Configuration Annotations
  • context Configuration Namespace
  • Enhanced AspectJ Support
  • jms Configuration Namespace
  • Annotation-driven Web MVC Controllers

32
context XML Schema Namespace (1)
  • Spring 2.5 introduces a new configuration
    namespace context
  • ltcontextproperty-placeholder /gt
  • Shortcut for a PropertyPlaceholderConfigurer
  • ltcontextannotation-config /gt
  • Shortcut for activating JSR-250 annotations,
    _at_Autowired, Spring 2.0s _at_Required,
    _at_PersistenceContext, _at_PersistenceUnit, _at_EJB,
    _at_WebServiceClient, _at_WebServiceRef
  • ltcontextcomponent-scan /gt
  • Completely new feature for Spring 2.5
    autodetects annotated components and
    automatically registers them as Spring beans!
  • Also triggers activation of annotations supported
    by the annotation-config tag

33
context XML Schema Namespace (2)
  • continued
  • ltcontextload-time-weaver /gt
  • Activates a Spring LoadTimeWeaver for the
    application context
  • ltcontextmbean-export /gt
  • Shortcut for AnnotationMBeanExporter, which
    activates exporting of JMX MBeans by detecting
    _at_ManagedResource annotations on Spring managed
    components
  • ltcontextspring-configured /gt
  • Enables dependency injection for non-managed
    components instantiated outside of the bean
    factory, typically annotated with _at_Configurable
  • Depends on AspectJ compile-time or load-time
    weaving

34
context Namespace Example
  • lt!-- resolves all properties against the
  • specified properties files --gt
  • ltcontextproperty-placeholder
  • locationjdbc.properties,mail.properties /gt
  • lt!-- activates common configuration annotations
  • JSR-250, _at_Autowired, _at_Required, etc. --gt
  • ltcontextannotation-config /gt
  • lt!-- scans the classpath autodetects all classes
  • annotated with _at_Component, _at_Service,
  • _at_Repository, or _at_Controller and automatically
  • registers them as Spring-managed components --gt
  • ltcontextcomponent-scan
  • base-packagemypackage.services /gt

35
Annotated Component Example
  • package mypackage.services
  • _at_Service
  • public class MyService implements
    MyServiceInterface
  • _at_Resource(namemyDataSource)
  • private DataSource dataSource
  • _at_Autowired
  • public void injectServices(ServiceA a, ServiceB
    b)
  • _at_PostConstruct
  • public void initialize()
  • _at_PreDestroy
  • public void shutdown()
  • lt!-- Not even a plain XML ltbeangt tag is
    necessary! --gt
  • ltcontextcomponent-scan base-packagemypackage.se
    rvices /gt

36
Agenda Part 2 Configuration
  • Support for Configuration Annotations
  • context Configuration Namespace
  • Enhanced AspectJ Support
  • jms Configuration Namespace
  • Annotation-driven Web MVC Controllers

37
AspectJ Pointcut bean(name)
  • New bean(name) pointcut element
  • For use in AspectJ-based pointcut expressions
  • In conjunction with ltaopconfiggt
  • Matches specific beans by name rather than by
    type
  • Leverages the availability of named beans
  • Supports pattern matching

ltaopadvisor pointcutexecution(bean(Service
)) advice-refaccessCounter /gt
38
AspectJ Load-Time Weaving
  • Support for AspectJ load-time weaving
  • Via Springs LoadTimeWeaver
  • as used, for example, by Springs JPA support
  • Driven by AspectJ META-INF/aop.xml files
  • For any supported platform
  • Via Springs generic VM agent (i.e.,
    spring-agent.jar)
  • With various application servers Tomcat,
    GlassFish, OC4J

ltcontextload-time-weaver aspectj-weavingon /gt
39
_at_Configurable Revisited
  • Spring 2.0 introduced _at_Configurable
  • For components whose lifecycle is not managed by
    a Spring ApplicationContext
  • e.g., instantiated directly with the new
    operator
  • or by a third-party framework
  • Enables dependency injection to any object
  • Depends on AspectJ weaving
  • Spring 2.5 supports _at_Configurable via load-time
    weaving!
  • AspectJ compiler is no longer necessary
  • Combines nicely with annotation-driven
    configuration
  • _at_Autowired, _at_Resource, _at_PostConstruct, etc.

40
_at_Configurable Applied
  • lt!- configures AspectJ bean configurer aspect
    --gt
  • lt!- spring-aspects.jar is required on the
    classpath --gt
  • lt!- ClassLoader needs to be weaving-capable
    --gt
  • ltcontextload-time-weaver aspectj-weavingon /gt
  • ltcontextspring-configured /gt
  • _at_Configurable
  • public class MyDomainObject
  • _at_Autowired
  • private MyService myService
  • // The following domain object will be configured
    by
  • // Spring!
  • MyDomainObject obj new MyDomainObject()

41
Traditional lttxannotation-driven /gt
  • lt!- automatically detects annotated components
    --gt
  • lttxannotation-driven transaction-managertxManag
    er /gt
  • ltbean idtxManager
  • classorg.springframework.jta.JtaTransactionMa
    nager /gt
  • lt!- Proxied only allowed to use _at_Transactional
    on public,
  • externally called methods! --gt
  • ltbean idaccountService classdemo.AccountServi
    ce /gt

42
_at_Transactional with AspectJ
  • lt!- configures AspectJ bean configurer aspect
    --gt
  • lt!- spring-aspects.jar is required on the
    classpath --gt
  • lt!- ClassLoader needs to be weaving-capable
    --gt
  • ltcontextload-time-weaver aspectj-weavingon /gt
  • lttxannotation-driven modeaspectj
  • transaction-managertxManager /gt
  • ltbean idtxManager
  • classorg.springframework.jta.JtaTransactionMa
    nager /gt
  • lt!- Woven allowed to use _at_Transactional on any
  • method! --gt
  • ltbean idaccountService classdemo.AccountServi
    ce /gt

43
Agenda Part 2 Configuration
  • Support for Configuration Annotations
  • context Configuration Namespace
  • Enhanced AspectJ Support
  • jms Configuration Namespace
  • Annotation-driven Web MVC Controllers

44
JMS Message Listener Containers
Spring 2.0 introduced the message listener
container concept for JMS
ltbean id"myMessageListenerContainer" class
"org.springframework.jms.listener.DefaultMessageLi
stenerContainer"/gt ltproperty name"connectionFac
tory" ref"myConnectionFactory"/gt ltproperty
name"destinationName" value"myQueue"/gt
ltproperty name"messageListener"
ref"myListener"/gt ltproperty name"transactionMa
nager" ref"myTransactionManager"/gtlt/beangt ltbean
idtransactionManager classorg.springframew
ork.transaction.jta.JtaTransactionManager/gtltbea
n idmyListener classexample.MyMessageListener
Impl psomeDao-refmyDao/gt
45
jms XML Schema Namespace
Spring 2.5 introduces a new namespace for JMS
lt!-- standard JMS message listener container
--gt ltjmslistener-container connection-factory"
myConnectionFactory" transaction-manager"myTran
sactionManager"gt ltjmslistener
destination"myQueue1" ref"myListener1"/gt
ltjmslistener destination"myQueue2"
ref"myListener2"/gt lt/jmslistener-containergt lt
!-- JCA-based JMS message listener container
--gt ltjmsjca-listener-container
resource-adapter"myResourceAdapter"
transaction-manager"myTransactionManager"gt
ltjmslistener destination"myQueue1"
ref"myListener1"/gt ltjmslistener
destination"myQueue2" ref"myListener2"/gt lt/jms
jca-listener-containergt
46
Agenda Part 2 Configuration
  • Support for Configuration Annotations
  • context Configuration Namespace
  • Enhanced AspectJ Support
  • jms Configuration Namespace
  • Annotation-driven Web MVC Controllers

47
Annotation-driven Web MVC Controllers
  • Spring 2.5 introduces support for
    annotation-driven Controllers
  • Available for both Servlet MVC and Portlet MVC
  • POJO-based
  • Annotate your class with _at_Controller
  • No need to extend base classes or implement a
    specific interface
  • Can even avoid dependencies on Servlet and
    Portlet APIs altogether!
  • Next generation of the traditional
    MultiActionController approach
  • Map requests directly onto a particular
    controller method via _at_RequestMapping
  • Bind request parameters to method parameters via
    _at_RequestParam
  • Bidirectional access to the model via
    _at_ModelAttribute
  • Store form data across multiple requests via
    _at_SessionAttributes

48
PetClinic ClinicController
MultiActionController-style handler mappings
_at_Controller public class ClinicController
private final Clinic clinic _at_Autowired
public ClinicController(Clinic clinic)
this.clinic clinic // Relies on the
RequestToViewNameTranslator to determine the
// logical view name based on the request URL.
_at_RequestMapping("/welcome.do") public void
welcomeHandler() // Returns a plain
ModelMap object instead of a ModelAndView, //
thus leveraging convention-based model attribute
names. _at_RequestMapping("/vets.do") public
ModelMap vetsHandler() return new
ModelMap(this.clinic.getVets())
49
PetClinic EditPetForm (1)
Session based form setup
_at_Controller _at_RequestMapping("/editPet.do") _at_Sessio
nAttributes("pet") public class EditPetForm
// ... _at_RequestMapping(type "GET") public
String setupForm( _at_RequestParam("petId") int
petId, ModelMap model) Pet pet
this.clinic.loadPet(petId)
model.addAttribute("pet", pet) return
"petForm" // ...
50
PetClinic EditPetForm (2)
Session based form processing
// EditPetForm continued ...
_at_ModelAttribute("types") public
CollectionltPetTypegt populatePetTypes()
return this.clinic.getPetTypes()
_at_RequestMapping(type "POST") public String
processSubmit( _at_ModelAttribute("pet") Pet
pet, BindingResult result, SessionStatus
status) new PetValidator().validate(pet,
result) if (result.hasErrors()) return
"petForm" else this.clinic.storePet
(pet) status.setComplete() return
"redirectowner.do?ownerId"
pet.getOwner().getId()
51
Agenda Part 3 TestContext Framework
  • Introduction
  • Key Abstractions
  • Examples

52
The Spring TestContext Framework
  • Spring 2.5 introduces new annotation-driven unit
    and integration testing support the Spring
    TestContext Framework
  • Powerful, flexible, extensible, and loosely
    coupled
  • Employs convention over configuration
  • Configured solely via annotations
  • Reasonable defaults that can be overridden
  • Agnostic of the underlying testing framework
  • Out-of-the-box support for JUnit 3.8, JUnit 4.4,
    and TestNG 5.5
  • Compelling alternative to Spring 2.0s base test
    classes for JUnit 3.8
  • Consistent support of Springs core configuration
    annotations (e.g., _at_Autowired, _at_Resource,
    _at_Transactional, etc.)
  • Supports Spring-specific integration testing
    functionality such as
  • context management and caching
  • dependency injection of test fixtures
  • transactional test management with default
    rollback semantics

53
Agenda Part 3 TestContext Framework
  • Introduction
  • Key Abstractions
  • Examples

54
TestContext Framework Key Abstractions
  • The core of the framework consists of the
    TestContext and TestContextManager classes and
    the TestExecutionListener interface.
  • TestContext encapsulates the context of the
    executing test
  • TestContextManager manages a TestContext and
    signals events to all registered
    TestExecutionListeners
  • TestExecutionListener defines a listener API for
    reacting to test execution events, configurable
    via _at_TestExecutionListeners. Spring provides the
    following implementations
  • DependencyInjectionTestExecutionListener
  • DirtiesContextTestExecutionListener
  • TransactionalTestExecutionListener

55
TestContext Framework Annotations
  • TestExecutionListeners
  • _at_TestExecutionListeners
  • Application Contexts
  • _at_ContextConfiguration and _at_DirtiesContext
  • Dependency Injection
  • _at_Autowired, _at_Qualifier, _at_Resource, _at_Required,
    etc.
  • Transactions
  • _at_Transactional, _at_NotTransactional,
    _at_TransactionConfiguration, _at_Rollback,
    _at_BeforeTransaction, and _at_AfterTransaction
  • Testing Profiles (JUnit only)
  • _at_IfProfileValue and _at_ProfileValueSourceConfigurati
    on
  • JUnit extensions
  • _at_ExpectedException, _at_Timed, _at_Repeat

56
TestContext Framework Support Classes
  • JUnit 3.8
  • AbstractJUnit38SpringContextTests
  • AbstractTransactionalJUnit38SpringContextTests
  • JUnit 4.4
  • AbstractJUnit4SpringContextTests
  • AbstractTransactionalJUnit4SpringContextTests
  • SpringJUnit4ClassRunner used to instrument POJO
    test classes in conjunction with JUnit 4s
    _at_RunWith annotation
  • TestNG 5.5
  • AbstractTestNGSpringContextTests
  • AbstractTransactionalTestNGSpringContextTests

57
Agenda Part 3 TestContext Framework
  • Introduction
  • Key Abstractions
  • Examples

58
PetClinic AbstractClinicTests
Using base support class
// Loads AbstractClinicTests-context.xml _at_ContextC
onfiguration public abstract class
AbstractClinicTests extends AbstractTransaction
alJUnit4SpringContextTests _at_Autowired
protected Clinic clinic _at_Test public void
getVets() CollectionltVetgt vets
this.clinic.getVets() // Use the inherited
SimpleJdbcTemplate to verify the // results
of the query. assertEquals("JDBC query must
show the same number of vets",
this.simpleJdbcTemplate.queryForInt(
"SELECT COUNT(0) FROM VETS"), vets.size())
// ...
59
PetClinic AbstractClinicTests
POJO configuration
_at_RunWith(SpringJUnit4ClassRunner.class) _at_Transacti
onal _at_ContextConfiguration public abstract class
AbstractClinicTests protected
SimpleJdbcTemplate simpleJdbcTemplate
_at_Autowired public void setDataSource(DataSource
dataSource) this.simpleJdbcTemplate new
SimpleJdbcTemplate(dataSource) // the
rest of the class remains the same.
60
AbstractClinicTests-context.xml
lt?xml version"1.0" encoding"UTF-8"?gt ltbeans
xmlns"http//www.springframework.org/schema/beans
" ... gt ltcontextproperty-placeholder
locationclasspathjdbc.properties
/gt ltcontextannotation-config
/gt lttxannotation-driven /gt ltbean
iddataSource classorg.sfw.jdbc.datasource.
DriverManagerDataSource pdriverClassNamej
dbc.driverClassName purljdbc.url
pusernamejdbc.username
ppasswordjdbc.password /gt lt/beansgt
61
PetClinic HibernateClinicTests
// Loads AbstractClinicTests-context.xml // and
HibernateClinicTests-context.xml _at_ContextConfigura
tion public class HibernateClinicTests extends
AbstractClinicTests // HibernateClinicTests
-context.xml ltbean class"org.sfw.samples.petcli
nic.hibernate.HibernateClinic" /gt ltbean
id"sessionFactory" class"org.sfw.orm.hiberna
te3.LocalSessionFactoryBean
pdataSource-ref"dataSource
pmappingResources"petclinic.hbm.xml"gt lt!-
remaining properties --gt lt/beangt ltbean
id"transactionManager" class"org.sfw.orm.hib
ernate3.HibernateTransactionManager
psessionFactory-ref"sessionFactory" /gt ltbean
class"org.sfw.dao.annotation.PersistenceExcepti
onTranslationPostProcessor" /gt
62
Summary (1)
  • Spring 2.5 builds on the strong 2.0 foundation
  • With updated support for Java standards
  • And a focus on ease of configuration
  • Spring 2.5 embraces Java 6 and Java EE 5 as well
    as OSGi
  • Spring as a traditional Java EE framework
  • Or Spring as an application framework in an OSGi
    environment
  • Same programming model!

63
Summary (2)
  • Spring 2.5 embraces further configuration
    annotations and special-purpose XML namespaces
  • as a straightforward addition to Spring's
    standard bean definition model
  • annotation-driven autowiring
  • annotation-driven component detection
  • Spring 2.5 simplifies web MVC development with
    annotation-driven Controllers
  • The Spring TestContext Framework provides new
    opportunities for simplified and enhanced unit
    and integration testing

64
For More Information
  • Spring Batch Dave Syer will be presenting on
    Spring Batch - a New Member of the Spring
    Portfolio at 1515 today
  • PetClinic sample application included in the
    full Spring 2.5 distribution
  • Spring Reference Manualhttp//static.springframe
    work.org/spring/docs/2.5.x/reference/
  • Spring Forumshttp//forum.springframework.org/
  • Spring JIRAhttp//opensource.atlassian.com/proje
    cts/spring/

65
  • World-class technical conference for the Spring
    community
  • Experience 3 full days with over 60 sessions
    across 5 technical tracks
  • Essential Spring
  • Enterprise Integration
  • Rich Web
  • Application Architecture and Design
  • Emerging Tech
  • Enjoy the amenities of a five-star beach resort
  • Converse with Spring team, peers, and industry
    experts
  • Visit http//www.thespringexperience.com for more
    information and registration

66
Demo
67
QA
  • Sam Brannen
  • sam.brannen_at_interface21.com
Write a Comment
User Comments (0)
About PowerShow.com