Go to file
Chris Beams ebea9ec66c Introduce reserved default profile support
AbstractEnvironment and subclasses now register a reserved default
profile named literally 'default' such that with no action on the part
of the user, beans defined against the 'default' profile will be
registered - if no other profiles are explicitly activated.

For example, given the following three files a.xml, b.xml and c.xml:

    a.xml
    -----
    <beans> <!-- no 'profile' attribute -->
        <bean id="a" class="com.acme.A"/>
    </beans>

    b.xml
    -----
    <beans profile="default">
        <bean id="b" class="com.acme.B"/>
    </beans>

    c.xml
    -----
    <beans profile="custom">
        <bean id="c" class="com.acme.C"/>
    </beans>

bootstrapping all of the files in a Spring ApplicationContext as
follows will result in beans 'a' and 'b', but not 'c' being registered:

    ApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("a.xml");
    ctx.load("b.xml");
    ctx.load("c.xml");
    ctx.refresh();
    ctx.containsBean("a"); // true
    ctx.containsBean("b"); // true
    ctx.containsBean("c"); // false

whereas activating the 'custom' profile will result in beans 'a' and
'c', but not 'b' being registered:

    ApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("a.xml");
    ctx.load("b.xml");
    ctx.load("c.xml");
    ctx.getEnvironment().setActiveProfiles("custom");
    ctx.refresh();
    ctx.containsBean("a"); // true
    ctx.containsBean("b"); // false
    ctx.containsBean("c"); // true

that is, once the 'custom' profile is activated, beans defined against
the the reserved default profile are no longer registered. Beans not
defined against any profile ('a') are always registered regardless of
which profiles are active, and of course beans registered
against specific active profiles ('c') are registered.

The reserved default profile is, in practice, just another 'default
profile', as might be added through calling env.setDefaultProfiles() or
via the 'spring.profiles.default' property.  The only difference is that
the reserved default is added automatically by AbstractEnvironment
implementations.  As such, any call to setDefaultProfiles() or value set
for the 'spring.profiles.default' will override the reserved default
profile.  If a user wishes to add their own default profile while
keeping the reserved default profile as well, it will need to be
explicitly redeclared, e.g.:

    env.addDefaultProfiles("my-default-profile", "default")

The reserved default profile(s) are determined by the value returned
from AbstractEnvironment#getReservedDefaultProfiles().  This protected
method may be overridden by subclasses in order to customize the
set of reserved default profiles.

Issue: SPR-8203

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4334 50f2f4bb-b051-0410-bef5-90022cba6387
2011-05-20 03:49:15 +00:00
build-spring-framework SPR-8352 Init and apply MappedInterceptors from AbstractHandlerMapping 2011-05-19 16:45:25 +00:00
org.springframework.aop Introduce @EnableTransactionManagement 2011-05-06 19:10:25 +00:00
org.springframework.asm Merge 3.1.0 development branch into trunk 2010-10-25 19:48:20 +00:00
org.springframework.aspects revised cache abstraction 2011-05-18 18:34:41 +00:00
org.springframework.beans Introduce reserved default profile support 2011-05-20 03:49:15 +00:00
org.springframework.context revised cache abstraction 2011-05-18 18:34:41 +00:00
org.springframework.context.support moved cache abstraction from context.support to context 2011-02-07 17:41:25 +00:00
org.springframework.core Introduce reserved default profile support 2011-05-20 03:49:15 +00:00
org.springframework.expression SPR-8211: property accessor ordering correction and removal of unnecessary duplicates 2011-05-12 16:40:44 +00:00
org.springframework.instrument Include license.txt and notice.txt in module JARs 2011-02-09 06:56:40 +00:00
org.springframework.instrument.tomcat Include license.txt and notice.txt in module JARs 2011-02-09 06:56:40 +00:00
org.springframework.integration-tests Add MockEnvironment to .integration-tests 2011-05-11 07:51:32 +00:00
org.springframework.jdbc SPR-6922 deprecated SimpleJdbcTemplate/SimpleJdbcOperations/SimpleJdbcDaoSupport in favor of JdbcTemplate/NamedParameterJdbcTemplate and related interfaces support classes 2011-04-14 18:44:40 +00:00
org.springframework.jms Include license.txt and notice.txt in module JARs 2011-02-09 06:56:40 +00:00
org.springframework.orm Fix generics and serialization warnings 2011-05-06 19:00:14 +00:00
org.springframework.oxm SPR-8296 - Extension for CastorMarshaller - additional unmarshaller properties 2011-05-19 14:01:35 +00:00
org.springframework.spring-library Merge 3.1.0 development branch into trunk 2010-10-25 19:48:20 +00:00
org.springframework.spring-parent Updating JUnit and TestNG versions for IDEs and Maven. 2011-03-28 19:59:09 +00:00
org.springframework.test Update MockEnvironment / MockPropertySource types 2011-05-06 18:57:41 +00:00
org.springframework.transaction Introduce @EnableTransactionManagement 2011-05-06 19:10:25 +00:00
org.springframework.web @RequestMapping.consumes() and produces() now default to an empty array, instead of */* 2011-05-18 11:34:47 +00:00
org.springframework.web.portlet Include license.txt and notice.txt in module JARs 2011-02-09 06:56:40 +00:00
org.springframework.web.servlet SPR-8352 Init and apply MappedInterceptors from AbstractHandlerMapping 2011-05-19 16:45:25 +00:00
org.springframework.web.struts [SPR-7850][SPR-7851] Upgraded to JUnit 4.8.1 and TestNG 5.12.1; added changelog entries for 3.1.0.M1. 2010-12-30 08:00:58 +00:00
spring-framework-reference SPR-7353 Doc update for consumes/produces + changelog update 2011-05-19 13:05:53 +00:00
src/test/java/org/springframework/core/env Merge 3.1.0 development branch into trunk 2010-10-25 19:48:20 +00:00
.gitignore M1 cut of environment, profiles and property work (SPR-7508) 2011-01-03 09:04:34 +00:00
build.properties Merge 3.1.0 development branch into trunk 2010-10-25 19:48:20 +00:00
build.versions [SPR-7850][SPR-7851] Upgraded to JUnit 4.8.1 and TestNG 5.12.1; added changelog entries for 3.1.0.M1. 2010-12-30 08:00:58 +00:00
ci-build.properties adding properties file to simplify ant use in Bamboo CI build 2008-12-17 15:47:14 +00:00
eclipse-code-formatter.xml h2 embedded db support; updated formatting conventions not to auto-format javadoc; added hsqldb and h2 to jdbc maven pom as optional deps 2009-05-09 22:27:05 +00:00
spring-framework.ipr Merge 3.1.0 development branch into trunk 2010-10-25 19:48:20 +00:00
spring-framework.psf Renamed org.springframework.instrument.classloading module to org.springframework.instrument.tomcat 2009-09-25 12:51:58 +00:00