Clarify semantics for multiple profiles in @Profile
This commit is contained in:
parent
fafb823e8d
commit
96e6406b4b
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -26,15 +26,16 @@ import org.springframework.core.env.AbstractEnvironment;
|
||||||
import org.springframework.core.env.ConfigurableEnvironment;
|
import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates that a component is eligible for registration when one or more {@linkplain
|
* Indicates that a component is eligible for registration when one or more
|
||||||
* #value specified profiles} are active.
|
* {@linkplain #value specified profiles} are active.
|
||||||
*
|
*
|
||||||
* <p>A <em>profile</em> is a named logical grouping that may be activated
|
* <p>A <em>profile</em> is a named logical grouping that may be activated
|
||||||
* programmatically via {@link ConfigurableEnvironment#setActiveProfiles} or declaratively
|
* programmatically via {@link ConfigurableEnvironment#setActiveProfiles} or declaratively
|
||||||
* through setting the {@link AbstractEnvironment#ACTIVE_PROFILES_PROPERTY_NAME
|
* by setting the {@link AbstractEnvironment#ACTIVE_PROFILES_PROPERTY_NAME
|
||||||
* spring.profiles.active} property, usually through JVM system properties, as an
|
* spring.profiles.active} property as a JVM system property, as an
|
||||||
* environment variable, or for web applications as a Servlet context parameter in
|
* environment variable, or as a Servlet context parameter in {@code web.xml}
|
||||||
* {@code web.xml}.
|
* for web applications. Profiles may also be activated declaratively in
|
||||||
|
* integration tests via the {@code @ActiveProfiles} annotation.
|
||||||
*
|
*
|
||||||
* <p>The {@code @Profile} annotation may be used in any of the following ways:
|
* <p>The {@code @Profile} annotation may be used in any of the following ways:
|
||||||
* <ul>
|
* <ul>
|
||||||
|
|
@ -46,33 +47,36 @@ import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
*
|
*
|
||||||
* <p>If a {@code @Configuration} class is marked with {@code @Profile}, all of the
|
* <p>If a {@code @Configuration} class is marked with {@code @Profile}, all of the
|
||||||
* {@code @Bean} methods and {@link Import @Import} annotations associated with that class
|
* {@code @Bean} methods and {@link Import @Import} annotations associated with that class
|
||||||
* will be bypassed unless one or more of the specified profiles are active. This is very
|
* will be bypassed unless one or more of the specified profiles are active. This is
|
||||||
* similar to the behavior in Spring XML: if the {@code profile} attribute of the
|
* analogous to the behavior in Spring XML: if the {@code profile} attribute of the
|
||||||
* {@code beans} element is supplied e.g., {@code <beans profile="p1,p2">}, the
|
* {@code beans} element is supplied e.g., {@code <beans profile="p1,p2">}, the
|
||||||
* {@code beans} element will not be parsed unless profiles 'p1' and/or 'p2' have been
|
* {@code beans} element will not be parsed unless at least profile 'p1' or 'p2' has been
|
||||||
* activated. Likewise, if a {@code @Component} or {@code @Configuration} class is marked
|
* activated. Likewise, if a {@code @Component} or {@code @Configuration} class is marked
|
||||||
* with {@code @Profile({"p1", "p2"})}, that class will not be registered/processed unless
|
* with {@code @Profile({"p1", "p2"})}, that class will not be registered or processed unless
|
||||||
* profiles 'p1' and/or 'p2' have been activated.
|
* at least profile 'p1' or 'p2' has been activated.
|
||||||
*
|
*
|
||||||
* <p>If a given profile is prefixed with the NOT operator ({@code !}), the annotated
|
* <p>If a given profile is prefixed with the NOT operator ({@code !}), the annotated
|
||||||
* will be registered if the profile is <em>not</em> active. e.g., for
|
* component will be registered if the profile is <em>not</em> active — for example,
|
||||||
* {@code @Profile({"p1", "!p2"})}, registration will occur if profile 'p1' is active or
|
* given {@code @Profile({"p1", "!p2"})}, registration will occur if profile 'p1' is active or
|
||||||
* if profile 'p2' is not active.
|
* if profile 'p2' is <em>not</em> active.
|
||||||
*
|
*
|
||||||
* <p>If the {@code @Profile} annotation is omitted, registration will occur, regardless
|
* <p>If the {@code @Profile} annotation is omitted, registration will occur regardless
|
||||||
* of which (if any) profiles are active.
|
* of which (if any) profiles are active.
|
||||||
*
|
*
|
||||||
* <p>When defining Spring beans via XML, the {@code "profile"} attribute of the
|
* <p>When defining Spring beans via XML, the {@code "profile"} attribute of the
|
||||||
* {@code <beans>} element may be used. See the documentation in
|
* {@code <beans>} element may be used. See the documentation in the
|
||||||
* {@code spring-beans} XSD (version 3.1 or greater) for details.
|
* {@code spring-beans} XSD (version 3.1 or greater) for details.
|
||||||
*
|
*
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
|
* @author Sam Brannen
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
* @see ConfigurableEnvironment#setActiveProfiles
|
* @see ConfigurableEnvironment#setActiveProfiles
|
||||||
* @see ConfigurableEnvironment#setDefaultProfiles
|
* @see ConfigurableEnvironment#setDefaultProfiles
|
||||||
* @see AbstractEnvironment#ACTIVE_PROFILES_PROPERTY_NAME
|
* @see AbstractEnvironment#ACTIVE_PROFILES_PROPERTY_NAME
|
||||||
* @see AbstractEnvironment#DEFAULT_PROFILES_PROPERTY_NAME
|
* @see AbstractEnvironment#DEFAULT_PROFILES_PROPERTY_NAME
|
||||||
|
* @see Conditional
|
||||||
|
* @see org.springframework.test.context.ActiveProfiles
|
||||||
*/
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target({ElementType.TYPE, ElementType.METHOD})
|
@Target({ElementType.TYPE, ElementType.METHOD})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue