|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2013 the original author or authors. |
| 2 | + * Copyright 2002-2015 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
26 | 26 | import org.springframework.core.env.ConfigurableEnvironment;
|
27 | 27 |
|
28 | 28 | /**
|
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. |
31 | 31 | *
|
32 | 32 | * <p>A <em>profile</em> is a named logical grouping that may be activated
|
33 | 33 | * 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. |
38 | 39 | *
|
39 | 40 | * <p>The {@code @Profile} annotation may be used in any of the following ways:
|
40 | 41 | * <ul>
|
|
46 | 47 | *
|
47 | 48 | * <p>If a {@code @Configuration} class is marked with {@code @Profile}, all of the
|
48 | 49 | * {@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 |
51 | 52 | * {@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 |
53 | 54 | * 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. |
56 | 57 | *
|
57 | 58 | * <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 — 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. |
61 | 62 | *
|
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 |
63 | 64 | * of which (if any) profiles are active.
|
64 | 65 | *
|
65 | 66 | * <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 |
67 | 68 | * {@code spring-beans} XSD (version 3.1 or greater) for details.
|
68 | 69 | *
|
69 | 70 | * @author Chris Beams
|
70 | 71 | * @author Phillip Webb
|
| 72 | + * @author Sam Brannen |
71 | 73 | * @since 3.1
|
72 | 74 | * @see ConfigurableEnvironment#setActiveProfiles
|
73 | 75 | * @see ConfigurableEnvironment#setDefaultProfiles
|
74 | 76 | * @see AbstractEnvironment#ACTIVE_PROFILES_PROPERTY_NAME
|
75 | 77 | * @see AbstractEnvironment#DEFAULT_PROFILES_PROPERTY_NAME
|
| 78 | + * @see Conditional |
| 79 | + * @see org.springframework.test.context.ActiveProfiles |
76 | 80 | */
|
77 | 81 | @Retention(RetentionPolicy.RUNTIME)
|
78 | 82 | @Target({ElementType.TYPE, ElementType.METHOD})
|
|
0 commit comments