Spring 3.1 Features Worth Knowing About
(Available For Download Today)

Rossen Stoyanchev, Software Engineer




                                                                     CONFIDENTIAL
                                       © 2010 SpringSource, A division of VMware. All rights reserved
Agenda


 Environment

 Java Configuration DSL

 Cache Abstraction




                           CONFIDENTIAL   2
Moving an Application Across Environments




       TRANSFER SERVICE                     DEV



         ACCOUNT DAO

                                            QA
         DATA SOURCE




                                            PROD




                           CONFIDENTIAL            3
Environment-Specific Properties In XML




                                                Property Source:
                                                dev/database.properties




        Property Source: Java system property


                                            dev/database.properties

                                            qa/database.properties
 java -DENV=prod ...
                                            prod/database.properties


                             CONFIDENTIAL                                 4
Environment-Specific Properties In Java

                             Property Source:
                             Java system property?




                       CONFIDENTIAL                  5
Spring EL Expressions in Spring 3.0




 Easier to see where properties originate from




                                CONFIDENTIAL      6
What About “Structural” Differences ?




                CONFIDENTIAL            7
Environment-Specific Configuration in XML




  prod/database-context.xml




                                         dev/database-context.xml



                                             Choose from multiple
  app-context.xml                            files to accommodate
                                             differences

                              CONFIDENTIAL                          8
Environment-Specific Configuration in Java




                                      Accommodate
                                      differences in code




                       CONFIDENTIAL                         9
Spring 3.1 “Environment” Abstraction

 A concrete representation with two key aspects
 • 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.




                                   CONFIDENTIAL                                     10
Managing Property Sources

 In standalone code




 In a Web application
 • Implement ApplicationContextInitializer
 • Register via contextInitializerClasses context parameter in web.xml

 Default property sources
 • JVM properties
 • System envrionment variables



                                  CONFIDENTIAL                           11
Accessing Environment Properties

 In standalone code




 Via @Autowired or EnvironmentAware interface

 In configuration (via placeholders)



 <context:property-placeholder/> also now falls back on
 Environment property sources


                                 CONFIDENTIAL              12
Beans Profiles With XML

 Assign all beans to profile



                            Multiple profiles can be listed


 Assign enclosed beans to a profile




                                  CONFIDENTIAL                13
Bean Profiles In Java




                        CONFIDENTIAL   14
Bean Profile Activation

 In code




 In Web applications




                          CONFIDENTIAL   15
Agenda


 Environment

 Java Configuration DSL

 Cache Abstraction




                           CONFIDENTIAL   16
Custom XML Namespaces

 Custom XML namespaces have become very popular
 • In Spring and in other frameworks

 Succinct and highly expressive




 Each namespace element can result in the registration of any
 number of bean definitions

 Question:
 How do get the same benefits in Java configuration?



                                       CONFIDENTIAL              17
Feature Specifications

 Java configuration equivalent to an XML namespace




 Declared in @FeatureConfiguration classes
                                    Beans declared elsewhere
                                    can be autowired in.




 Results in same bean declarations as <tx:annotation-driven />

                              CONFIDENTIAL                     18
FeatureSpecifications Are Designed For Ease of Use




                       CONFIDENTIAL                  19
Agenda


 Environment

 Java Configuration DSL

 Cache Abstraction




                           CONFIDENTIAL   20
Spring 3.1 Cache Abstraction

 CacheManager and Cache abstractions
 • org.springframework.cache

 Backend adapters for EhCache, GemFire, Coherence, etc.

 Cache namespace
 • <cache:annotation-driven />

 CacheManager SPI
 • EhCacheManager
 • GemFireCacheManager




                               CONFIDENTIAL                21
Annotation-Based Caching

                    Cache name




                                  Custom key




                                       Cache condition




                       CONFIDENTIAL                      22
Spring 3.1 M1 Blog Series:
----------------------------------

http://blog.springsource.com/2008/03/26/spring-java-
configuration-whats-new-in-m3/

https://github.com/cbeams/spring-3.1-profiles-xml
https://github.com/cbeams/spring-3.1-profiles-java
https://github.com/cbeams/spring-3.1-featurespec
https://github.com/rstoyanchev/spring-3.1-mvc-java-config

Review updated Spring Reference Documentation

Provide feedback via JIRA and Forums

                                 CONFIDENTIAL          23
Thank You




   CONFIDENTIAL   24

Spring 3.1 Features Worth Knowing About

  • 1.
    Spring 3.1 FeaturesWorth Knowing About (Available For Download Today) Rossen Stoyanchev, Software Engineer CONFIDENTIAL © 2010 SpringSource, A division of VMware. All rights reserved
  • 2.
    Agenda  Environment  JavaConfiguration DSL  Cache Abstraction CONFIDENTIAL 2
  • 3.
    Moving an ApplicationAcross Environments TRANSFER SERVICE DEV ACCOUNT DAO QA DATA SOURCE PROD CONFIDENTIAL 3
  • 4.
    Environment-Specific Properties InXML Property Source: dev/database.properties Property Source: Java system property dev/database.properties qa/database.properties java -DENV=prod ... prod/database.properties CONFIDENTIAL 4
  • 5.
    Environment-Specific Properties InJava Property Source: Java system property? CONFIDENTIAL 5
  • 6.
    Spring EL Expressionsin Spring 3.0  Easier to see where properties originate from CONFIDENTIAL 6
  • 7.
    What About “Structural”Differences ? CONFIDENTIAL 7
  • 8.
    Environment-Specific Configuration inXML prod/database-context.xml dev/database-context.xml Choose from multiple app-context.xml files to accommodate differences CONFIDENTIAL 8
  • 9.
    Environment-Specific Configuration inJava Accommodate differences in code CONFIDENTIAL 9
  • 10.
    Spring 3.1 “Environment”Abstraction  A concrete representation with two key aspects • 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. CONFIDENTIAL 10
  • 11.
    Managing Property Sources In standalone code  In a Web application • Implement ApplicationContextInitializer • Register via contextInitializerClasses context parameter in web.xml  Default property sources • JVM properties • System envrionment variables CONFIDENTIAL 11
  • 12.
    Accessing Environment Properties In standalone code  Via @Autowired or EnvironmentAware interface  In configuration (via placeholders)  <context:property-placeholder/> also now falls back on Environment property sources CONFIDENTIAL 12
  • 13.
    Beans Profiles WithXML  Assign all beans to profile Multiple profiles can be listed  Assign enclosed beans to a profile CONFIDENTIAL 13
  • 14.
    Bean Profiles InJava CONFIDENTIAL 14
  • 15.
    Bean Profile Activation In code  In Web applications CONFIDENTIAL 15
  • 16.
    Agenda  Environment  JavaConfiguration DSL  Cache Abstraction CONFIDENTIAL 16
  • 17.
    Custom XML Namespaces Custom XML namespaces have become very popular • In Spring and in other frameworks  Succinct and highly expressive  Each namespace element can result in the registration of any number of bean definitions  Question: How do get the same benefits in Java configuration? CONFIDENTIAL 17
  • 18.
    Feature Specifications  Javaconfiguration equivalent to an XML namespace  Declared in @FeatureConfiguration classes Beans declared elsewhere can be autowired in.  Results in same bean declarations as <tx:annotation-driven /> CONFIDENTIAL 18
  • 19.
    FeatureSpecifications Are DesignedFor Ease of Use CONFIDENTIAL 19
  • 20.
    Agenda  Environment  JavaConfiguration DSL  Cache Abstraction CONFIDENTIAL 20
  • 21.
    Spring 3.1 CacheAbstraction  CacheManager and Cache abstractions • org.springframework.cache  Backend adapters for EhCache, GemFire, Coherence, etc.  Cache namespace • <cache:annotation-driven />  CacheManager SPI • EhCacheManager • GemFireCacheManager CONFIDENTIAL 21
  • 22.
    Annotation-Based Caching Cache name Custom key Cache condition CONFIDENTIAL 22
  • 23.
    Spring 3.1 M1Blog Series: ---------------------------------- http://blog.springsource.com/2008/03/26/spring-java- configuration-whats-new-in-m3/ https://github.com/cbeams/spring-3.1-profiles-xml https://github.com/cbeams/spring-3.1-profiles-java https://github.com/cbeams/spring-3.1-featurespec https://github.com/rstoyanchev/spring-3.1-mvc-java-config Review updated Spring Reference Documentation Provide feedback via JIRA and Forums CONFIDENTIAL 23
  • 24.
    Thank You CONFIDENTIAL 24