The first milestone release of Spring 3.1 has just been published [1], and this article kicks off a series of posts where I and other team members will walk through each of the major features. Even in the first milestone there's already a lot to talk about!
- Bean definition profiles
- Unified property management through Spring's new
Environment
abstraction
- Enhancements to Java-based configuration with
@Feature
methods
- Expanded MVC namespace support and a Java-based configuration equivalent
- Streaming support and new interception model for the
RestTemplate
API
- Comprehensive caching support
- New
c:
XML namespace for concise configuration of constructor injection
Today I'll be covering the first item -- a new feature we call
bean definition profiles. One of our most frequent requests has been to provide a mechanism in the core container that allows for registration of different beans in different environments. The word "environment" can mean different things to different users, but a typical scenario might be registering monitoring infrastructure only when deploying an application into a performance environment, or registering customized implementations of beans for customer A vs. customer B deployments. Perhaps one of the most common cases would be working against a standalone datasource in development vs looking up that same datasource from JNDI when in QA or production. Bean definition profiles represent a general-purpose way to satisfy use cases of this kind, and we'll explore the latter use case in the examples below.
Get hands-on with a sample
I've developed a small sample to accompany this post, and you might like to take a moment now to check it out (if not, don't worry; you don't need the code to read along below). Just follow the instructions on the README at https://github.com/cbeams/spring-3.1-profiles-xml. If you're not familiar with Git, the README has instructions…