Download - Spring 3.1 Features Worth Knowing About
© 2010 SpringSource, A division of VMware. All rights reserved
CONFIDENTIALCONFIDENTIAL
Spring 3.1 Features Worth Knowing About (Available For Download Today)
Rossen Stoyanchev, Software Engineer
2CONFIDENTIAL 2CONFIDENTIAL 2
Environment
Java Configuration DSL
Cache Abstraction
Agenda
3CONFIDENTIAL 3CONFIDENTIAL
Moving an Application Across Environments
DATA SOURCE
TRANSFER SERVICE
ACCOUNT DAO
DEV
QA
PROD
4CONFIDENTIAL 4CONFIDENTIAL
Environment-Specific Properties In XML
dev/database.properties
qa/database.properties
prod/database.propertiesjava -DENV=prod ...
Property Source:dev/database.properties
Property Source: Java system property
5CONFIDENTIAL 5CONFIDENTIAL
Environment-Specific Properties In Java
Property Source: Java system property?
6CONFIDENTIAL 6CONFIDENTIAL
Spring EL Expressions in Spring 3.0
Easier to see where properties originate from
7CONFIDENTIAL 7CONFIDENTIAL
What About “Structural” Differences ?
8CONFIDENTIAL 8CONFIDENTIAL
prod/database-context.xml
dev/database-context.xml
app-context.xml
Environment-Specific Configuration in XML
Choose from multiple files to accommodate differences
9CONFIDENTIAL 9CONFIDENTIAL
Environment-Specific Configuration in Java
Accommodate differences in code
10CONFIDENTIAL 10CONFIDENTIAL
A concrete representation with two key aspects
• Property Sources
• Bean Profiles
Bean Profile:
A logical group of bean definitions. Registered only if the profile is active.
Property Source:
A variety of sources: property files, system properties, servlet context, JNDI, etc.
Spring 3.1 “Environment” Abstraction
11CONFIDENTIAL 11CONFIDENTIAL
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
Managing Property Sources
12CONFIDENTIAL 12CONFIDENTIAL
In standalone code
Via @Autowired or EnvironmentAware interface
In configuration (via placeholders)
<context:property-placeholder/> also now falls back on Environment property sources
Accessing Environment Properties
13CONFIDENTIAL 13CONFIDENTIAL
Assign all beans to profile
Assign enclosed beans to a profile
Beans Profiles With XML
Multiple profiles can be listed
14CONFIDENTIAL 14CONFIDENTIAL
Bean Profiles In Java
15CONFIDENTIAL 15CONFIDENTIAL
In code
In Web applications
Bean Profile Activation
16CONFIDENTIAL 16CONFIDENTIAL 16
Environment
Java Configuration DSL
Cache Abstraction
Agenda
17CONFIDENTIAL 17CONFIDENTIAL
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?
Custom XML Namespaces
18CONFIDENTIAL 18CONFIDENTIAL
Java configuration equivalent to an XML namespace
Declared in @FeatureConfiguration classes
Results in same bean declarations as <tx:annotation-driven />
Feature Specifications
Beans declared elsewhere can be autowired in.
19CONFIDENTIAL 19CONFIDENTIAL
FeatureSpecifications Are Designed For Ease of Use
20CONFIDENTIAL 20CONFIDENTIAL 20
Environment
Java Configuration DSL
Cache Abstraction
Agenda
21CONFIDENTIAL 21CONFIDENTIAL
CacheManager and Cache abstractions
• org.springframework.cache
Backend adapters for EhCache, GemFire, Coherence, etc.
Cache namespace
• <cache:annotation-driven />
CacheManager SPI
• EhCacheManager
• GemFireCacheManager
Spring 3.1 Cache Abstraction
22CONFIDENTIAL 22CONFIDENTIAL
Annotation-Based Caching
Cache name
Custom key
Cache condition
23CONFIDENTIAL 23CONFIDENTIAL
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-xmlhttps://github.com/cbeams/spring-3.1-profiles-javahttps://github.com/cbeams/spring-3.1-featurespechttps://github.com/rstoyanchev/spring-3.1-mvc-java-config
Review updated Spring Reference Documentation
Provide feedback via JIRA and Forums
24CONFIDENTIAL 24CONFIDENTIAL
Thank You