Skip to content

Commit 96e6406

Browse files
committed
Clarify semantics for multiple profiles in @Profile
1 parent fafb823 commit 96e6406

File tree

1 file changed

+21
-17
lines changed
  • spring-context/src/main/java/org/springframework/context/annotation

1 file changed

+21
-17
lines changed

spring-context/src/main/java/org/springframework/context/annotation/Profile.java

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,15 +26,16 @@
2626
import org.springframework.core.env.ConfigurableEnvironment;
2727

2828
/**
29-
* Indicates that a component is eligible for registration when one or more {@linkplain
30-
* #value specified profiles} are active.
29+
* Indicates that a component is eligible for registration when one or more
30+
* {@linkplain #value specified profiles} are active.
3131
*
3232
* <p>A <em>profile</em> is a named logical grouping that may be activated
3333
* programmatically via {@link ConfigurableEnvironment#setActiveProfiles} or declaratively
34-
* through setting the {@link AbstractEnvironment#ACTIVE_PROFILES_PROPERTY_NAME
35-
* spring.profiles.active} property, usually through JVM system properties, as an
36-
* environment variable, or for web applications as a Servlet context parameter in
37-
* {@code web.xml}.
34+
* by setting the {@link AbstractEnvironment#ACTIVE_PROFILES_PROPERTY_NAME
35+
* spring.profiles.active} property as a JVM system property, as an
36+
* environment variable, or as a Servlet context parameter in {@code web.xml}
37+
* for web applications. Profiles may also be activated declaratively in
38+
* integration tests via the {@code @ActiveProfiles} annotation.
3839
*
3940
* <p>The {@code @Profile} annotation may be used in any of the following ways:
4041
* <ul>
@@ -46,33 +47,36 @@
4647
*
4748
* <p>If a {@code @Configuration} class is marked with {@code @Profile}, all of the
4849
* {@code @Bean} methods and {@link Import @Import} annotations associated with that class
49-
* will be bypassed unless one or more of the specified profiles are active. This is very
50-
* similar to the behavior in Spring XML: if the {@code profile} attribute of the
50+
* will be bypassed unless one or more of the specified profiles are active. This is
51+
* analogous to the behavior in Spring XML: if the {@code profile} attribute of the
5152
* {@code beans} element is supplied e.g., {@code <beans profile="p1,p2">}, the
52-
* {@code beans} element will not be parsed unless profiles 'p1' and/or 'p2' have been
53+
* {@code beans} element will not be parsed unless at least profile 'p1' or 'p2' has been
5354
* activated. Likewise, if a {@code @Component} or {@code @Configuration} class is marked
54-
* with {@code @Profile({"p1", "p2"})}, that class will not be registered/processed unless
55-
* profiles 'p1' and/or 'p2' have been activated.
55+
* with {@code @Profile({"p1", "p2"})}, that class will not be registered or processed unless
56+
* at least profile 'p1' or 'p2' has been activated.
5657
*
5758
* <p>If a given profile is prefixed with the NOT operator ({@code !}), the annotated
58-
* will be registered if the profile is <em>not</em> active. e.g., for
59-
* {@code @Profile({"p1", "!p2"})}, registration will occur if profile 'p1' is active or
60-
* if profile 'p2' is not active.
59+
* component will be registered if the profile is <em>not</em> active &mdash; for example,
60+
* given {@code @Profile({"p1", "!p2"})}, registration will occur if profile 'p1' is active or
61+
* if profile 'p2' is <em>not</em> active.
6162
*
62-
* <p>If the {@code @Profile} annotation is omitted, registration will occur, regardless
63+
* <p>If the {@code @Profile} annotation is omitted, registration will occur regardless
6364
* of which (if any) profiles are active.
6465
*
6566
* <p>When defining Spring beans via XML, the {@code "profile"} attribute of the
66-
* {@code <beans>} element may be used. See the documentation in
67+
* {@code <beans>} element may be used. See the documentation in the
6768
* {@code spring-beans} XSD (version 3.1 or greater) for details.
6869
*
6970
* @author Chris Beams
7071
* @author Phillip Webb
72+
* @author Sam Brannen
7173
* @since 3.1
7274
* @see ConfigurableEnvironment#setActiveProfiles
7375
* @see ConfigurableEnvironment#setDefaultProfiles
7476
* @see AbstractEnvironment#ACTIVE_PROFILES_PROPERTY_NAME
7577
* @see AbstractEnvironment#DEFAULT_PROFILES_PROPERTY_NAME
78+
* @see Conditional
79+
* @see org.springframework.test.context.ActiveProfiles
7680
*/
7781
@Retention(RetentionPolicy.RUNTIME)
7882
@Target({ElementType.TYPE, ElementType.METHOD})

0 commit comments

Comments
 (0)