SlideShare a Scribd company logo
1 of 83
Spring 3.1 to 3.2
  in a Nutshell
   Sam Brannen
    Swiftmind
Speaker Profile
•   Spring & Java consultant @ Swiftmind
•   Developing Java for over 14 years
•   Spring Framework Core Developer
•   Spring Trainer
•   Lead author of “Spring in a Nutshell”
Show of hands…
Agenda
•   Major Themes in 3.x
•   Environment and Profiles
•   Java-based Configuration
•   Testing
•   Caching
•   MVC and REST
•   Servlet 3.0
•   3.2 Roadmap
Major Themes in Spring 3.0
Java-based configuration
custom stereotypes
annotated factory methods
JSR-330 – DI for Java
Spring Expression Language
REST support in Spring MVC
Portlet API 2.0
JSR-303 – bean validation
Java EE 6 support: JPA 2.0, JSF 2.0
Major Themes in Spring 3.1
– Environment abstraction
– Java-based application configuration
– @Configuration class test support
– High-level cache API
– Customizable @MVC processing
– Flash maps and redirect attributes
– Explicit support for Servlet 3.0
Environment and Profiles
Environment Abstraction
– Injectable environment abstraction API
     • org.springframework.core.env.Environment

– Two core concepts
     • Property Sources
     • Bean Profiles


Property Source:                  Bean Profile:

A variety of sources: property    A logical group of bean
files, system properties,         definitions. Registered only if
servlet context, JNDI, etc.       the profile is active.
Property Source Abstraction
– Property source

– Property resolution

– Placeholders
PropertySource(s)
– PropertySource
  • a single property source


– PropertySources
  • a hierarchy of PropertySource objects
  • potentially varying across deployment environments
Property Resolution SPI

– org.springframework.core.env.PropertyResolver

– Environment extends PropertyResolver
Custom Placeholder Resolution

– dependent on the actual environment

– PropertySourcesPlaceholderConfigurer
  supersedes PropertyPlaceholderConfigurer
Managing Property Sources
– Stand-alone code




– Web application
  • Implement ApplicationContextInitializer
  • Register via contextInitializerClasses context parameter in
    web.xml
Accessing Properties
– By injecting the Environment
Bean Definition Profiles
– Logical grouping of bean definitions
  • for activation in specific environments
  • e.g., dev, staging, prod
  • possibly different deployment platforms


– Configuration
  • XML via <beans profile=“…”>
  • Java-based configuration via @Profile
Configuring Profiles in XML
– All bean definitions




– Subset of bean definitions
Configuring Profiles in Java Config




– @Profile can also be used on components
  • @Component, @Service, @Repository, etc.   26
Profile Activation Options
– programmatically

– system property

– in web.xml

– in tests via @ActiveProfiles
Activating Profiles…
 programmatically
Activating Profiles…
       via system properties


-Dspring.profiles.active=“dev”

-Dspring.profiles.default=“common”
Activating Profiles…
    in web apps
Activating Profiles…
 in integration tests
Java-based Configuration
Java Config ~= XML
– XML namespaces  @Enable*
– FactoryBeans  builders
– GenericXmlContextLoader 
  AnnotationConfigContextLoader

– Not a one-to-one mapping
  • Make the most of what Java has to offer
  • Intuitive annotation-oriented container configuration
Typical Infrastructure Setup
– Transactions

– Scheduling

– MVC customization

– AOP
@Enable* Annotations
– Applied at the class-level on @Configuration
  classes

– Roughly equivalent to their XML namespace
  counterparts
@Enable* in 3.1
– @EnableTransactionManagement
– @EnableCaching
– @EnableAsync
– @EnableScheduling
– @EnableAspectJAutoProxy
– @EnableLoadTimeWeaving
– @EnableSpringConfigured
– @EnableWebMvc
Hibernate and JPA
– Hibernate LocalSessionFactoryBuilder API
  • Hibernate 4 replacement for both
    LocalSessionFactoryBean and
    AnnotationSessionFactoryBean


– XML-free JPA configuration
  • LocalContainerEntityManagerFactoryBean has a
    new property
  • packagesToScan: analogous to
    AnnotationSessionFactoryBean
Java Configuration Example


                 Actually:
                 LocalSessionFactoryBuilder
New Testing Features in 3.1
– @Configuration class support
– Environment profile support
– SmartContextLoader
– AnnotationConfigContextLoader
– DelegatingSmartContextLoader
– Updated context cache key generation
SmartContextLoader SPI
– Supersedes ContextLoader
– Strategy for loading application contexts
– From @Configuration classes or resource
  locations
– Supports environment profiles
@ContextConfiguration
accepts a new `classes` attribute...
Ex: @Configuration Test #1
Ex: @Configuration Test #2
Caching
Caching Abstraction
– Declarative caching for Spring applications
  • Minimal impact on code
  • Plug in various caching solutions
Caching Abstraction
– Key annotations
  • @Cacheable
  • @CacheEvict
Cache Key
– All method arguments used by default




– Use SpEL to select more specifically (use
  class, method, or argument name)
Conditional Caching
Cache Providers (1/2)
– Cache and CacheManager SPI
  • org.springframework.cache


– Cache Implementations
  • EhCacheCache
  • ConcurrentMapCache and
    ConcurrentMapCacheFactoryBean
Cache Providers (2/2)
– CacheManager Implementations
  •   EhCacheCacheManager
  •   ConcurrentMapCacheManager
  •   SimpleCacheManager
  •   NoOpCacheManager


– Any other implementation can be plugged in
  • GemFire, Coherence, etc.
Cache Configuration
– Cache namespace
  • <cache:annotation-driven />
  • “cacheManager” bean
MVC and REST
@MVC 3.0 Config
– Built-in defaults
  • Based on DispatcherServlet.properties

– Spring MVC namespace
  • <mvc:annotation:driven>, <mvc:interceptors>, …
Java-based @MVC 3.1 Config
– Most Spring MVC configuration is in Java already
   • @Controller, @RequestMapping, etc.

– Servlet 3.0 enhancements will further reduce the
  need for web.xml

– XML namespace is convenient but …
   • Not transparent
   • Not easy to offer the right degree of customization



– … What should a Java equivalent to the MVC
  namespace look like?
@EnableWebMvc
– Enables Spring MVC default configuration
  • Registers components expected by the
    DispatcherServlet




– Allows for configuration similar to the
  Spring MVC namespace
  • … and the DispatcherServlet.properties combined
A More Complete Example …
– Add component scanning for @Controllers
  and other beans
Q: Where is the “Enabled”
        Configuration ?!
– A: a framework-provided @Configuration class
  (actually DelegatingWebMvcConfiguration)
How Do I Customize All This?
– Simply implement the WebMvcConfigurer
  interface
                              Allows selective overriding
HandlerMethod Abstraction
– HandlerMethod
   • A proper abstraction for the selected “handler” in Spring MVC

– Not just for @RequestMapping methods
   • Also @InitBinder, @ModelAttribute, @ExceptionHandler
     methods

– “HandlerMethod” support classes
   • RequestMappingHandlerMapping
   • RequestMappingHandlerAdapter
   • ExceptionHandlerExceptionResolver
Path Variables in the Model
– @PathVariable arguments automatically
  added to the model




                            These can be deleted
URI Templates in Redirect Strings
– URL templates supported in “redirect:”
  strings




                  Expanded from model attributes,
                 which now include @PathVariables
URI Template Vars in Data Binding
– URI template variables used in data binding
Matching MediaTypes < @MVC 3.1
  – Using the 'headers' condition
Matching MediaTypes in @MVC 3.1
  – The 'consumes' and 'produces' conditions



                   If not matched, results in:
                   UNSUPPORTED_MEDIA_TYPE (415)




                          If not matched, results in:
                          NOT_ACCEPTABLE (406)
Servlet 3.0
Servlet 3.0 Containers

• Tomcat 7 and GlassFish 3
  – Explicitly supported

• While preserving compatibility with Servlet
  2.4+
XML-free Web-app Config
• Support for XML-free web application setup
  – no web.xml


• Made possible via:
  – Servlet 3.0's ServletContainerInitializer
  – Spring 3.1's
    AnnotationConfigWebApplicationContext
  – Spring 3.1’s environment abstraction
Native Servlet 3.0 in @MVC
• Asynchronous request processing

• Standard Servlet 3.0 file upload
  – behind Spring's MultipartResolver abstraction
Bonus
"c:" Namespace
– Shortcut for <constructor-arg>
  • inline argument values
  • analogous to existing "p:" namespace
– Use of constructor argument names
  • recommended for readability
  • debug symbols have to be available in the
    application's class files
Spring 3.1 in a Nutshell
•   Environment and Profiles
•   Java-based Configuration and @Enable*
•   Testing with @Configuration and Profiles
•   Cache Abstraction
•   MVC and REST Improvements
•   Servlet 3.0
•   c: Namespace
Spring 3.2 Roadmap
Build System & Source Control
• Moved from Subversion to Git(hub)
  – Spring 3.1.1
  – github.com/SpringSource/spring-framework

• Moving from Spring Build (i.e., Ant + Ivy) to
  Gradle

• SPR-8120
Servlet 3.0/3.1 Async Requests
• Servlet 3.0/3.1 asynchronous request
  processing
  – Explicit support in Spring @MVC


• SPR-8517
Java EE 7
• JPA 2.1 (JSR-338)
   – Building on JPA 2.0 support in Spring 3.0
   – SPR-8194

• JSF 2.2 (JSR-344)
   – Specification compatibility
   – SPR-8104

• JMS 2.0 (JSR-343)
   – Long overdue, major overhaul to JMS
   – Exploring a native JMS API style for use with Spring
   – SPR-8197
Caching
• Support for JCache (JSR-107) compliant cache providers
   – JCacheCacheManager/Cache adapters for Spring's SPI
   – JCacheManager/JCacheFactoryBean

• Support for JCache's standardized caching annotations
   – ideally automatically through Spring’s
     <cache:annotation-driven>

• SPR-8774
Validation
• Bean Validation 1.1 (JSR-349)
  – Specification compatibility
  – Building on 1.0 support in Spring 3.0


• SPR-8199
Spring Core
• Migrate from CGLIB to Javassist
   – For class-based proxies (AOP)
   – SPR-8190


• Bean definition visibility and overriding
   –   Final bean definitions
   –   Profile-scoped beans
   –   @Bean methods override XML beans
   –   SPR-8189
Spring MVC Testing Support
• Unit tests with Mock MVC classes
  – Simulates the DispatcherServlet


• Integration tests with XmlWebApplicationContext
  – Configured via @ContextConfiguration and other
    annotations
  – Loaded via a new ContextLoader
In Closing…
Further Resources
• Spring Framework
  – http://springframework.org
  – Spring Reference Manual
  – JavaDoc
• Spring Forums
  – http://forum.springframework.org
• Spring JIRA
  – http://jira.springframework.org
Blogs
• SpringSource Team Blog – category 3.1
  – http://blog.springsource.com/category/spring/31/


• Swiftmind Blog
  – http://www.swiftmind.com/blog/
Q&A

Sam Brannen

twitter: @sam_brannen
www.slideshare.net/sbrannen
www.swiftmind.com


“Spring in a Nutshell”
       http://oreilly.com/catalog/9780596801946
      available from O’Reilly in 2012

More Related Content

What's hot

Polygot Java EE on the GraalVM
Polygot Java EE on the GraalVMPolygot Java EE on the GraalVM
Polygot Java EE on the GraalVMRyan Cuprak
 
Batching and Java EE (jdk.io)
Batching and Java EE (jdk.io)Batching and Java EE (jdk.io)
Batching and Java EE (jdk.io)Ryan Cuprak
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with GradleRyan Cuprak
 
Workshop Framework(J2EE/OSGi/RCP)
Workshop Framework(J2EE/OSGi/RCP)Workshop Framework(J2EE/OSGi/RCP)
Workshop Framework(J2EE/OSGi/RCP)Summer Lu
 
Maven 3 Overview
Maven 3  OverviewMaven 3  Overview
Maven 3 OverviewMike Ensor
 
Spring 3.1 in a Nutshell - JAX London 2011
Spring 3.1 in a Nutshell - JAX London 2011Spring 3.1 in a Nutshell - JAX London 2011
Spring 3.1 in a Nutshell - JAX London 2011Sam Brannen
 
Maven Basics - Explained
Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - ExplainedSmita Prasad
 
Spring Framework 4.1
Spring Framework 4.1Spring Framework 4.1
Spring Framework 4.1Sam Brannen
 
Play Framework and Activator
Play Framework and ActivatorPlay Framework and Activator
Play Framework and ActivatorKevin Webber
 
Cloud Foundry Open Tour India 2012 , Keynote
Cloud Foundry Open Tour India 2012 , KeynoteCloud Foundry Open Tour India 2012 , Keynote
Cloud Foundry Open Tour India 2012 , Keynoterajdeep
 
Triple E class DevOps with Hudson, Maven, Kokki/Multiconf and PyDev
Triple E class DevOps with Hudson, Maven, Kokki/Multiconf and PyDevTriple E class DevOps with Hudson, Maven, Kokki/Multiconf and PyDev
Triple E class DevOps with Hudson, Maven, Kokki/Multiconf and PyDevWerner Keil
 

What's hot (20)

Polygot Java EE on the GraalVM
Polygot Java EE on the GraalVMPolygot Java EE on the GraalVM
Polygot Java EE on the GraalVM
 
Batching and Java EE (jdk.io)
Batching and Java EE (jdk.io)Batching and Java EE (jdk.io)
Batching and Java EE (jdk.io)
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with Gradle
 
Workshop Framework(J2EE/OSGi/RCP)
Workshop Framework(J2EE/OSGi/RCP)Workshop Framework(J2EE/OSGi/RCP)
Workshop Framework(J2EE/OSGi/RCP)
 
Maven 3 Overview
Maven 3  OverviewMaven 3  Overview
Maven 3 Overview
 
Apache Maven 2 Part 2
Apache Maven 2 Part 2Apache Maven 2 Part 2
Apache Maven 2 Part 2
 
Apache maven 2 overview
Apache maven 2 overviewApache maven 2 overview
Apache maven 2 overview
 
Spring 3.1 in a Nutshell - JAX London 2011
Spring 3.1 in a Nutshell - JAX London 2011Spring 3.1 in a Nutshell - JAX London 2011
Spring 3.1 in a Nutshell - JAX London 2011
 
Maven Basics - Explained
Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - Explained
 
Maven tutorial
Maven tutorialMaven tutorial
Maven tutorial
 
Spring Framework 4.1
Spring Framework 4.1Spring Framework 4.1
Spring Framework 4.1
 
Wt unit 3 server side technology
Wt unit 3 server side technologyWt unit 3 server side technology
Wt unit 3 server side technology
 
Why Play Framework is fast
Why Play Framework is fastWhy Play Framework is fast
Why Play Framework is fast
 
Play Framework and Activator
Play Framework and ActivatorPlay Framework and Activator
Play Framework and Activator
 
Cloud Foundry Open Tour India 2012 , Keynote
Cloud Foundry Open Tour India 2012 , KeynoteCloud Foundry Open Tour India 2012 , Keynote
Cloud Foundry Open Tour India 2012 , Keynote
 
Maven advanced
Maven advancedMaven advanced
Maven advanced
 
Maven Introduction
Maven IntroductionMaven Introduction
Maven Introduction
 
Apache Maven In 10 Slides
Apache Maven In 10 SlidesApache Maven In 10 Slides
Apache Maven In 10 Slides
 
Maven
Maven Maven
Maven
 
Triple E class DevOps with Hudson, Maven, Kokki/Multiconf and PyDev
Triple E class DevOps with Hudson, Maven, Kokki/Multiconf and PyDevTriple E class DevOps with Hudson, Maven, Kokki/Multiconf and PyDev
Triple E class DevOps with Hudson, Maven, Kokki/Multiconf and PyDev
 

Similar to Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012

Spring Day | Spring 3.1 in a Nutshell | Sam Brannen
Spring Day | Spring 3.1 in a Nutshell | Sam BrannenSpring Day | Spring 3.1 in a Nutshell | Sam Brannen
Spring Day | Spring 3.1 in a Nutshell | Sam BrannenJAX London
 
Spring 3.1 in a Nutshell
Spring 3.1 in a NutshellSpring 3.1 in a Nutshell
Spring 3.1 in a NutshellSam Brannen
 
Testing Spring MVC and REST Web Applications
Testing Spring MVC and REST Web ApplicationsTesting Spring MVC and REST Web Applications
Testing Spring MVC and REST Web ApplicationsSam Brannen
 
Spring 3.1: a Walking Tour
Spring 3.1: a Walking TourSpring 3.1: a Walking Tour
Spring 3.1: a Walking TourJoshua Long
 
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010Arun Gupta
 
Java EE 8 Update
Java EE 8 UpdateJava EE 8 Update
Java EE 8 UpdateRyan Cuprak
 
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...Arun Gupta
 
Testing Web Apps with Spring Framework 3.2
Testing Web Apps with Spring Framework 3.2Testing Web Apps with Spring Framework 3.2
Testing Web Apps with Spring Framework 3.2Rossen Stoyanchev
 
Spring data presentation
Spring data presentationSpring data presentation
Spring data presentationOleksii Usyk
 
Spring design-juergen-qcon
Spring design-juergen-qconSpring design-juergen-qcon
Spring design-juergen-qconYiwei Ma
 
4. introduction to Asp.Net MVC - Part II
4. introduction to Asp.Net MVC - Part II4. introduction to Asp.Net MVC - Part II
4. introduction to Asp.Net MVC - Part IIRohit Rao
 
Java EE 6 & GlassFish = Less Code + More Power at CEJUG
Java EE 6 & GlassFish = Less Code + More Power at CEJUGJava EE 6 & GlassFish = Less Code + More Power at CEJUG
Java EE 6 & GlassFish = Less Code + More Power at CEJUGArun Gupta
 
JavaOne India 2011 - Servlets 3.0
JavaOne India 2011 - Servlets 3.0JavaOne India 2011 - Servlets 3.0
JavaOne India 2011 - Servlets 3.0Arun Gupta
 
Spring Framework 4.0 to 4.1
Spring Framework 4.0 to 4.1Spring Framework 4.0 to 4.1
Spring Framework 4.0 to 4.1Sam Brannen
 
Boston 2011 OTN Developer Days - Java EE 6
Boston 2011 OTN Developer Days - Java EE 6Boston 2011 OTN Developer Days - Java EE 6
Boston 2011 OTN Developer Days - Java EE 6Arun Gupta
 
Java EE 6 = Less Code + More Power
Java EE 6 = Less Code + More PowerJava EE 6 = Less Code + More Power
Java EE 6 = Less Code + More PowerArun Gupta
 
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnition
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnitionJava EE 6 & GlassFish = Less Code + More Power @ DevIgnition
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnitionArun Gupta
 

Similar to Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012 (20)

Spring Day | Spring 3.1 in a Nutshell | Sam Brannen
Spring Day | Spring 3.1 in a Nutshell | Sam BrannenSpring Day | Spring 3.1 in a Nutshell | Sam Brannen
Spring Day | Spring 3.1 in a Nutshell | Sam Brannen
 
Spring 3.1 in a Nutshell
Spring 3.1 in a NutshellSpring 3.1 in a Nutshell
Spring 3.1 in a Nutshell
 
Testing Spring MVC and REST Web Applications
Testing Spring MVC and REST Web ApplicationsTesting Spring MVC and REST Web Applications
Testing Spring MVC and REST Web Applications
 
Spring 3.1: a Walking Tour
Spring 3.1: a Walking TourSpring 3.1: a Walking Tour
Spring 3.1: a Walking Tour
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010
 
Next stop: Spring 4
Next stop: Spring 4Next stop: Spring 4
Next stop: Spring 4
 
Java EE 8 Update
Java EE 8 UpdateJava EE 8 Update
Java EE 8 Update
 
Lo nuevo en Spring 3.0
Lo nuevo  en Spring 3.0Lo nuevo  en Spring 3.0
Lo nuevo en Spring 3.0
 
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...
 
Testing Web Apps with Spring Framework 3.2
Testing Web Apps with Spring Framework 3.2Testing Web Apps with Spring Framework 3.2
Testing Web Apps with Spring Framework 3.2
 
Spring data presentation
Spring data presentationSpring data presentation
Spring data presentation
 
Spring design-juergen-qcon
Spring design-juergen-qconSpring design-juergen-qcon
Spring design-juergen-qcon
 
4. introduction to Asp.Net MVC - Part II
4. introduction to Asp.Net MVC - Part II4. introduction to Asp.Net MVC - Part II
4. introduction to Asp.Net MVC - Part II
 
Java EE 6 & GlassFish = Less Code + More Power at CEJUG
Java EE 6 & GlassFish = Less Code + More Power at CEJUGJava EE 6 & GlassFish = Less Code + More Power at CEJUG
Java EE 6 & GlassFish = Less Code + More Power at CEJUG
 
JavaOne India 2011 - Servlets 3.0
JavaOne India 2011 - Servlets 3.0JavaOne India 2011 - Servlets 3.0
JavaOne India 2011 - Servlets 3.0
 
Spring Framework 4.0 to 4.1
Spring Framework 4.0 to 4.1Spring Framework 4.0 to 4.1
Spring Framework 4.0 to 4.1
 
Boston 2011 OTN Developer Days - Java EE 6
Boston 2011 OTN Developer Days - Java EE 6Boston 2011 OTN Developer Days - Java EE 6
Boston 2011 OTN Developer Days - Java EE 6
 
Java EE 6 = Less Code + More Power
Java EE 6 = Less Code + More PowerJava EE 6 = Less Code + More Power
Java EE 6 = Less Code + More Power
 
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnition
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnitionJava EE 6 & GlassFish = Less Code + More Power @ DevIgnition
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnition
 

More from Sam Brannen

Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023
Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023
Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023Sam Brannen
 
Testing with JUnit 5 and Spring - Spring I/O 2022
Testing with JUnit 5 and Spring - Spring I/O 2022Testing with JUnit 5 and Spring - Spring I/O 2022
Testing with JUnit 5 and Spring - Spring I/O 2022Sam Brannen
 
JUnit 5 - Evolution and Innovation - SpringOne Platform 2019
JUnit 5 - Evolution and Innovation - SpringOne Platform 2019JUnit 5 - Evolution and Innovation - SpringOne Platform 2019
JUnit 5 - Evolution and Innovation - SpringOne Platform 2019Sam Brannen
 
JUnit 5: What's New and What's Coming - Spring I/O 2019
JUnit 5: What's New and What's Coming - Spring I/O 2019JUnit 5: What's New and What's Coming - Spring I/O 2019
JUnit 5: What's New and What's Coming - Spring I/O 2019Sam Brannen
 
JUnit 5 - New Opportunities for Testing on the JVM
JUnit 5 - New Opportunities for Testing on the JVMJUnit 5 - New Opportunities for Testing on the JVM
JUnit 5 - New Opportunities for Testing on the JVMSam Brannen
 
Get the Most out of Testing with Spring 4.2
Get the Most out of Testing with Spring 4.2Get the Most out of Testing with Spring 4.2
Get the Most out of Testing with Spring 4.2Sam Brannen
 
JUnit 5 - from Lambda to Alpha and beyond
JUnit 5 - from Lambda to Alpha and beyondJUnit 5 - from Lambda to Alpha and beyond
JUnit 5 - from Lambda to Alpha and beyondSam Brannen
 
Testing with Spring: An Introduction
Testing with Spring: An IntroductionTesting with Spring: An Introduction
Testing with Spring: An IntroductionSam Brannen
 
Testing with Spring 4.x
Testing with Spring 4.xTesting with Spring 4.x
Testing with Spring 4.xSam Brannen
 
Composable Software Architecture with Spring
Composable Software Architecture with SpringComposable Software Architecture with Spring
Composable Software Architecture with SpringSam Brannen
 
Testing Web Apps with Spring Framework 3.2
Testing Web Apps with Spring Framework 3.2Testing Web Apps with Spring Framework 3.2
Testing Web Apps with Spring Framework 3.2Sam Brannen
 
Spring Framework 4.0 - The Next Generation - Soft-Shake 2013
Spring Framework 4.0 - The Next Generation - Soft-Shake 2013Spring Framework 4.0 - The Next Generation - Soft-Shake 2013
Spring Framework 4.0 - The Next Generation - Soft-Shake 2013Sam Brannen
 
Spring 3.1 and MVC Testing Support - 4Developers
Spring 3.1 and MVC Testing Support - 4DevelopersSpring 3.1 and MVC Testing Support - 4Developers
Spring 3.1 and MVC Testing Support - 4DevelopersSam Brannen
 
Effective out-of-container Integration Testing - 4Developers
Effective out-of-container Integration Testing - 4DevelopersEffective out-of-container Integration Testing - 4Developers
Effective out-of-container Integration Testing - 4DevelopersSam Brannen
 
Spring 3.1 to 3.2 in a Nutshell - SDC2012
Spring 3.1 to 3.2 in a Nutshell - SDC2012Spring 3.1 to 3.2 in a Nutshell - SDC2012
Spring 3.1 to 3.2 in a Nutshell - SDC2012Sam Brannen
 
Spring 3.1 and MVC Testing Support
Spring 3.1 and MVC Testing SupportSpring 3.1 and MVC Testing Support
Spring 3.1 and MVC Testing SupportSam Brannen
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSam Brannen
 
Effective out-of-container Integration Testing
Effective out-of-container Integration TestingEffective out-of-container Integration Testing
Effective out-of-container Integration TestingSam Brannen
 
What's New in Spring 3.0
What's New in Spring 3.0What's New in Spring 3.0
What's New in Spring 3.0Sam Brannen
 
Modular Web Applications with OSGi
Modular Web Applications with OSGiModular Web Applications with OSGi
Modular Web Applications with OSGiSam Brannen
 

More from Sam Brannen (20)

Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023
Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023
Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023
 
Testing with JUnit 5 and Spring - Spring I/O 2022
Testing with JUnit 5 and Spring - Spring I/O 2022Testing with JUnit 5 and Spring - Spring I/O 2022
Testing with JUnit 5 and Spring - Spring I/O 2022
 
JUnit 5 - Evolution and Innovation - SpringOne Platform 2019
JUnit 5 - Evolution and Innovation - SpringOne Platform 2019JUnit 5 - Evolution and Innovation - SpringOne Platform 2019
JUnit 5 - Evolution and Innovation - SpringOne Platform 2019
 
JUnit 5: What's New and What's Coming - Spring I/O 2019
JUnit 5: What's New and What's Coming - Spring I/O 2019JUnit 5: What's New and What's Coming - Spring I/O 2019
JUnit 5: What's New and What's Coming - Spring I/O 2019
 
JUnit 5 - New Opportunities for Testing on the JVM
JUnit 5 - New Opportunities for Testing on the JVMJUnit 5 - New Opportunities for Testing on the JVM
JUnit 5 - New Opportunities for Testing on the JVM
 
Get the Most out of Testing with Spring 4.2
Get the Most out of Testing with Spring 4.2Get the Most out of Testing with Spring 4.2
Get the Most out of Testing with Spring 4.2
 
JUnit 5 - from Lambda to Alpha and beyond
JUnit 5 - from Lambda to Alpha and beyondJUnit 5 - from Lambda to Alpha and beyond
JUnit 5 - from Lambda to Alpha and beyond
 
Testing with Spring: An Introduction
Testing with Spring: An IntroductionTesting with Spring: An Introduction
Testing with Spring: An Introduction
 
Testing with Spring 4.x
Testing with Spring 4.xTesting with Spring 4.x
Testing with Spring 4.x
 
Composable Software Architecture with Spring
Composable Software Architecture with SpringComposable Software Architecture with Spring
Composable Software Architecture with Spring
 
Testing Web Apps with Spring Framework 3.2
Testing Web Apps with Spring Framework 3.2Testing Web Apps with Spring Framework 3.2
Testing Web Apps with Spring Framework 3.2
 
Spring Framework 4.0 - The Next Generation - Soft-Shake 2013
Spring Framework 4.0 - The Next Generation - Soft-Shake 2013Spring Framework 4.0 - The Next Generation - Soft-Shake 2013
Spring Framework 4.0 - The Next Generation - Soft-Shake 2013
 
Spring 3.1 and MVC Testing Support - 4Developers
Spring 3.1 and MVC Testing Support - 4DevelopersSpring 3.1 and MVC Testing Support - 4Developers
Spring 3.1 and MVC Testing Support - 4Developers
 
Effective out-of-container Integration Testing - 4Developers
Effective out-of-container Integration Testing - 4DevelopersEffective out-of-container Integration Testing - 4Developers
Effective out-of-container Integration Testing - 4Developers
 
Spring 3.1 to 3.2 in a Nutshell - SDC2012
Spring 3.1 to 3.2 in a Nutshell - SDC2012Spring 3.1 to 3.2 in a Nutshell - SDC2012
Spring 3.1 to 3.2 in a Nutshell - SDC2012
 
Spring 3.1 and MVC Testing Support
Spring 3.1 and MVC Testing SupportSpring 3.1 and MVC Testing Support
Spring 3.1 and MVC Testing Support
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. REST
 
Effective out-of-container Integration Testing
Effective out-of-container Integration TestingEffective out-of-container Integration Testing
Effective out-of-container Integration Testing
 
What's New in Spring 3.0
What's New in Spring 3.0What's New in Spring 3.0
What's New in Spring 3.0
 
Modular Web Applications with OSGi
Modular Web Applications with OSGiModular Web Applications with OSGi
Modular Web Applications with OSGi
 

Recently uploaded

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 

Recently uploaded (20)

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 

Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012

  • 1. Spring 3.1 to 3.2 in a Nutshell Sam Brannen Swiftmind
  • 2. Speaker Profile • Spring & Java consultant @ Swiftmind • Developing Java for over 14 years • Spring Framework Core Developer • Spring Trainer • Lead author of “Spring in a Nutshell”
  • 4. Agenda • Major Themes in 3.x • Environment and Profiles • Java-based Configuration • Testing • Caching • MVC and REST • Servlet 3.0 • 3.2 Roadmap
  • 5. Major Themes in Spring 3.0
  • 9. JSR-330 – DI for Java
  • 11. REST support in Spring MVC
  • 13. JSR-303 – bean validation
  • 14. Java EE 6 support: JPA 2.0, JSF 2.0
  • 15. Major Themes in Spring 3.1 – Environment abstraction – Java-based application configuration – @Configuration class test support – High-level cache API – Customizable @MVC processing – Flash maps and redirect attributes – Explicit support for Servlet 3.0
  • 17. Environment Abstraction – Injectable environment abstraction API • org.springframework.core.env.Environment – Two core concepts • Property Sources • Bean Profiles Property Source: Bean Profile: A variety of sources: property A logical group of bean files, system properties, definitions. Registered only if servlet context, JNDI, etc. the profile is active.
  • 18. Property Source Abstraction – Property source – Property resolution – Placeholders
  • 19. PropertySource(s) – PropertySource • a single property source – PropertySources • a hierarchy of PropertySource objects • potentially varying across deployment environments
  • 20. Property Resolution SPI – org.springframework.core.env.PropertyResolver – Environment extends PropertyResolver
  • 21. Custom Placeholder Resolution – dependent on the actual environment – PropertySourcesPlaceholderConfigurer supersedes PropertyPlaceholderConfigurer
  • 22. Managing Property Sources – Stand-alone code – Web application • Implement ApplicationContextInitializer • Register via contextInitializerClasses context parameter in web.xml
  • 23. Accessing Properties – By injecting the Environment
  • 24. Bean Definition Profiles – Logical grouping of bean definitions • for activation in specific environments • e.g., dev, staging, prod • possibly different deployment platforms – Configuration • XML via <beans profile=“…”> • Java-based configuration via @Profile
  • 25. Configuring Profiles in XML – All bean definitions – Subset of bean definitions
  • 26. Configuring Profiles in Java Config – @Profile can also be used on components • @Component, @Service, @Repository, etc. 26
  • 27. Profile Activation Options – programmatically – system property – in web.xml – in tests via @ActiveProfiles
  • 29. Activating Profiles… via system properties -Dspring.profiles.active=“dev” -Dspring.profiles.default=“common”
  • 30. Activating Profiles… in web apps
  • 31. Activating Profiles… in integration tests
  • 33. Java Config ~= XML – XML namespaces  @Enable* – FactoryBeans  builders – GenericXmlContextLoader  AnnotationConfigContextLoader – Not a one-to-one mapping • Make the most of what Java has to offer • Intuitive annotation-oriented container configuration
  • 34. Typical Infrastructure Setup – Transactions – Scheduling – MVC customization – AOP
  • 35. @Enable* Annotations – Applied at the class-level on @Configuration classes – Roughly equivalent to their XML namespace counterparts
  • 36. @Enable* in 3.1 – @EnableTransactionManagement – @EnableCaching – @EnableAsync – @EnableScheduling – @EnableAspectJAutoProxy – @EnableLoadTimeWeaving – @EnableSpringConfigured – @EnableWebMvc
  • 37. Hibernate and JPA – Hibernate LocalSessionFactoryBuilder API • Hibernate 4 replacement for both LocalSessionFactoryBean and AnnotationSessionFactoryBean – XML-free JPA configuration • LocalContainerEntityManagerFactoryBean has a new property • packagesToScan: analogous to AnnotationSessionFactoryBean
  • 38. Java Configuration Example Actually: LocalSessionFactoryBuilder
  • 39. New Testing Features in 3.1 – @Configuration class support – Environment profile support – SmartContextLoader – AnnotationConfigContextLoader – DelegatingSmartContextLoader – Updated context cache key generation
  • 40. SmartContextLoader SPI – Supersedes ContextLoader – Strategy for loading application contexts – From @Configuration classes or resource locations – Supports environment profiles
  • 41. @ContextConfiguration accepts a new `classes` attribute...
  • 45. Caching Abstraction – Declarative caching for Spring applications • Minimal impact on code • Plug in various caching solutions
  • 46. Caching Abstraction – Key annotations • @Cacheable • @CacheEvict
  • 47. Cache Key – All method arguments used by default – Use SpEL to select more specifically (use class, method, or argument name)
  • 49. Cache Providers (1/2) – Cache and CacheManager SPI • org.springframework.cache – Cache Implementations • EhCacheCache • ConcurrentMapCache and ConcurrentMapCacheFactoryBean
  • 50. Cache Providers (2/2) – CacheManager Implementations • EhCacheCacheManager • ConcurrentMapCacheManager • SimpleCacheManager • NoOpCacheManager – Any other implementation can be plugged in • GemFire, Coherence, etc.
  • 51. Cache Configuration – Cache namespace • <cache:annotation-driven /> • “cacheManager” bean
  • 53. @MVC 3.0 Config – Built-in defaults • Based on DispatcherServlet.properties – Spring MVC namespace • <mvc:annotation:driven>, <mvc:interceptors>, …
  • 54. Java-based @MVC 3.1 Config – Most Spring MVC configuration is in Java already • @Controller, @RequestMapping, etc. – Servlet 3.0 enhancements will further reduce the need for web.xml – XML namespace is convenient but … • Not transparent • Not easy to offer the right degree of customization – … What should a Java equivalent to the MVC namespace look like?
  • 55. @EnableWebMvc – Enables Spring MVC default configuration • Registers components expected by the DispatcherServlet – Allows for configuration similar to the Spring MVC namespace • … and the DispatcherServlet.properties combined
  • 56. A More Complete Example … – Add component scanning for @Controllers and other beans
  • 57. Q: Where is the “Enabled” Configuration ?! – A: a framework-provided @Configuration class (actually DelegatingWebMvcConfiguration)
  • 58. How Do I Customize All This? – Simply implement the WebMvcConfigurer interface Allows selective overriding
  • 59. HandlerMethod Abstraction – HandlerMethod • A proper abstraction for the selected “handler” in Spring MVC – Not just for @RequestMapping methods • Also @InitBinder, @ModelAttribute, @ExceptionHandler methods – “HandlerMethod” support classes • RequestMappingHandlerMapping • RequestMappingHandlerAdapter • ExceptionHandlerExceptionResolver
  • 60. Path Variables in the Model – @PathVariable arguments automatically added to the model These can be deleted
  • 61. URI Templates in Redirect Strings – URL templates supported in “redirect:” strings Expanded from model attributes, which now include @PathVariables
  • 62. URI Template Vars in Data Binding – URI template variables used in data binding
  • 63. Matching MediaTypes < @MVC 3.1 – Using the 'headers' condition
  • 64. Matching MediaTypes in @MVC 3.1 – The 'consumes' and 'produces' conditions If not matched, results in: UNSUPPORTED_MEDIA_TYPE (415) If not matched, results in: NOT_ACCEPTABLE (406)
  • 66. Servlet 3.0 Containers • Tomcat 7 and GlassFish 3 – Explicitly supported • While preserving compatibility with Servlet 2.4+
  • 67. XML-free Web-app Config • Support for XML-free web application setup – no web.xml • Made possible via: – Servlet 3.0's ServletContainerInitializer – Spring 3.1's AnnotationConfigWebApplicationContext – Spring 3.1’s environment abstraction
  • 68. Native Servlet 3.0 in @MVC • Asynchronous request processing • Standard Servlet 3.0 file upload – behind Spring's MultipartResolver abstraction
  • 69. Bonus
  • 70. "c:" Namespace – Shortcut for <constructor-arg> • inline argument values • analogous to existing "p:" namespace – Use of constructor argument names • recommended for readability • debug symbols have to be available in the application's class files
  • 71. Spring 3.1 in a Nutshell • Environment and Profiles • Java-based Configuration and @Enable* • Testing with @Configuration and Profiles • Cache Abstraction • MVC and REST Improvements • Servlet 3.0 • c: Namespace
  • 73. Build System & Source Control • Moved from Subversion to Git(hub) – Spring 3.1.1 – github.com/SpringSource/spring-framework • Moving from Spring Build (i.e., Ant + Ivy) to Gradle • SPR-8120
  • 74. Servlet 3.0/3.1 Async Requests • Servlet 3.0/3.1 asynchronous request processing – Explicit support in Spring @MVC • SPR-8517
  • 75. Java EE 7 • JPA 2.1 (JSR-338) – Building on JPA 2.0 support in Spring 3.0 – SPR-8194 • JSF 2.2 (JSR-344) – Specification compatibility – SPR-8104 • JMS 2.0 (JSR-343) – Long overdue, major overhaul to JMS – Exploring a native JMS API style for use with Spring – SPR-8197
  • 76. Caching • Support for JCache (JSR-107) compliant cache providers – JCacheCacheManager/Cache adapters for Spring's SPI – JCacheManager/JCacheFactoryBean • Support for JCache's standardized caching annotations – ideally automatically through Spring’s <cache:annotation-driven> • SPR-8774
  • 77. Validation • Bean Validation 1.1 (JSR-349) – Specification compatibility – Building on 1.0 support in Spring 3.0 • SPR-8199
  • 78. Spring Core • Migrate from CGLIB to Javassist – For class-based proxies (AOP) – SPR-8190 • Bean definition visibility and overriding – Final bean definitions – Profile-scoped beans – @Bean methods override XML beans – SPR-8189
  • 79. Spring MVC Testing Support • Unit tests with Mock MVC classes – Simulates the DispatcherServlet • Integration tests with XmlWebApplicationContext – Configured via @ContextConfiguration and other annotations – Loaded via a new ContextLoader
  • 81. Further Resources • Spring Framework – http://springframework.org – Spring Reference Manual – JavaDoc • Spring Forums – http://forum.springframework.org • Spring JIRA – http://jira.springframework.org
  • 82. Blogs • SpringSource Team Blog – category 3.1 – http://blog.springsource.com/category/spring/31/ • Swiftmind Blog – http://www.swiftmind.com/blog/
  • 83. Q&A Sam Brannen twitter: @sam_brannen www.slideshare.net/sbrannen www.swiftmind.com “Spring in a Nutshell” http://oreilly.com/catalog/9780596801946 available from O’Reilly in 2012