Go to file
Chris Beams f455b1e89a Support default profile (SPR-7508, SPR-7778)
'default' is now a reserved profile name, indicating
that any beans defined within that profile will be registered
unless another profile or profiles have been activated.

Examples below are expressed in XML, but apply equally when
using the @Profile annotation.

EXAMPLE 1:

        <beans>
            <beans profile="default">
                <bean id="foo" class="com.acme.EmbeddedFooImpl"/>
            </beans>
            <beans profile="production">
                <bean id="foo" class="com.acme.ProdFooImpl"/>
            </beans>
        </beans>

    In the case above, the EmbeddedFooImpl 'foo' bean will be
    registered if:
        a) no profile is active
        b) the 'default' profile has explicitly been made active

    The ProdFooImpl 'foo' bean will be registered if the 'production'
    profile is active.

EXAMPLE 2:

        <beans profile="default,xyz">
            <bean id="foo" class="java.lang.String"/>
        </beans>

    Bean 'foo' will be registered if any of the following are true:
        a) no profile is active
        b) 'xyz' profile is active
        c) 'default' profile has explicitly been made active
        d) both (b) and (c) are true

Note that the default profile is not to be confused with specifying no
profile at all.  When the default profile is specified, beans are
registered only if no other profiles are active; whereas when no profile
is specified, bean definitions are always registered regardless of which
profiles are active.

The default profile may be configured programmatically:

    environmnent.setDefaultProfile("embedded");

or declaratively through any registered PropertySource, e.g. system properties:

    -DdefaultSpringProfile=embedded

Assuming either of the above, example 1 could be rewritten as follows:

        <beans>
            <beans profile="embedded">
                <bean id="foo" class="com.acme.EmbeddedFooImpl"/>
            </beans>
            <beans profile="production">
                <bean id="foo" class="com.acme.ProdFooImpl"/>
            </beans>
        </beans>

It is unlikely that use of the default profile will make sense in
conjunction with a statically specified 'springProfiles' property.
For example, if 'springProfiles' is specified as a web.xml context
param, that profile will always be active for that application,
negating the possibility of default profile bean definitions ever
being registered.

The default profile is most useful for ensuring that a valid set of
bean definitions will always be registered without forcing users
to explictly specify active profiles.  In the embedded vs. production
examples above, it is assumed that the application JVM will be started
with -DspringProfiles=production when the application is in fact in
a production environment.  Otherwise, the embedded/default profile bean
definitions will always be registered.


git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3804 50f2f4bb-b051-0410-bef5-90022cba6387
2010-12-01 09:01:58 +00:00
build-spring-framework prepared for 3.0.5 release 2010-10-20 05:48:25 +00:00
org.springframework.aop Merge 3.1.0 development branch into trunk 2010-10-25 19:48:20 +00:00
org.springframework.asm Merge 3.1.0 development branch into trunk 2010-10-25 19:48:20 +00:00
org.springframework.aspects Add missing JPA dependency 2010-11-15 16:54:12 +00:00
org.springframework.beans Support default profile (SPR-7508, SPR-7778) 2010-12-01 09:01:58 +00:00
org.springframework.context Support default profile (SPR-7508, SPR-7778) 2010-12-01 09:01:58 +00:00
org.springframework.context.support SPR-7308 2010-10-29 17:17:10 +00:00
org.springframework.core Support default profile (SPR-7508, SPR-7778) 2010-12-01 09:01:58 +00:00
org.springframework.expression Merge 3.1.0 development branch into trunk 2010-10-25 19:48:20 +00:00
org.springframework.instrument Merge 3.1.0 development branch into trunk 2010-10-25 19:48:20 +00:00
org.springframework.instrument.tomcat Merge 3.1.0 development branch into trunk 2010-10-25 19:48:20 +00:00
org.springframework.integration-tests Fix .integration-tests build path errors 2010-11-15 19:15:29 +00:00
org.springframework.jdbc Merge 3.1.0 development branch into trunk 2010-10-25 19:48:20 +00:00
org.springframework.jms Merge 3.1.0 development branch into trunk 2010-10-25 19:48:20 +00:00
org.springframework.orm Merge 3.1.0 development branch into trunk 2010-10-25 19:48:20 +00:00
org.springframework.oxm Merge 3.1.0 development branch into trunk 2010-10-25 19:48:20 +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 Add hamcrest to beans pom in the right place to make tests compile 2010-11-16 17:12:32 +00:00
org.springframework.test SPR-7705: re-order rules and befores 2010-11-17 17:27:03 +00:00
org.springframework.transaction Merge 3.1.0 development branch into trunk 2010-10-25 19:48:20 +00:00
org.springframework.web Add missing ROME dep 2010-11-15 16:49:17 +00:00
org.springframework.web.portlet SPR-7703 2010-10-31 17:46:15 +00:00
org.springframework.web.servlet SPR-7707 - Unexpected behavior with class-level @RequestMappings 2010-11-08 14:56:35 +00:00
org.springframework.web.struts Merge 3.1.0 development branch into trunk 2010-10-25 19:48:20 +00:00
spring-framework-reference Docs 2010-10-13 14:19:48 +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 Add hamcrest to beans pom in the right place to make tests compile 2010-11-16 17:12:32 +00:00
build.properties Merge 3.1.0 development branch into trunk 2010-10-25 19:48:20 +00:00
build.versions + downgraded slf4j to 1.5.6 to solve IllegalAcessError with Hibernate 3.3 2010-02-04 17:10:31 +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