@Retention(value=RUNTIME) @Target(value={TYPE,METHOD}) @Documented public @interface Profile
A profile is a named logical grouping that may be activated
programmatically via ConfigurableEnvironment.setActiveProfiles(java.lang.String...)
or declaratively
by setting the spring.profiles.active
property as a JVM system property, as an
environment variable, or as a Servlet context parameter in web.xml
for web applications. Profiles may also be activated declaratively in
integration tests via the @ActiveProfiles
annotation.
The @Profile
annotation may be used in any of the following ways:
@Component
, including @Configuration
classes@Bean
methodIf a @Configuration
class is marked with @Profile
, all of the
@Bean
methods and @Import
annotations associated with that class
will be bypassed unless one or more of the specified profiles are active. This is
analogous to the behavior in Spring XML: if the profile
attribute of the
beans
element is supplied e.g., <beans profile="p1,p2">
, the
beans
element will not be parsed unless at least profile 'p1' or 'p2' has been
activated. Likewise, if a @Component
or @Configuration
class is marked
with @Profile({"p1", "p2"})
, that class will not be registered or processed unless
at least profile 'p1' or 'p2' has been activated.
If a given profile is prefixed with the NOT operator (!
), the annotated
component will be registered if the profile is not active — for example,
given @Profile({"p1", "!p2"})
, registration will occur if profile 'p1' is active or
if profile 'p2' is not active.
If the @Profile
annotation is omitted, registration will occur regardless
of which (if any) profiles are active.
When defining Spring beans via XML, the "profile"
attribute of the
<beans>
element may be used. See the documentation in the
spring-beans
XSD (version 3.1 or greater) for details.
ConfigurableEnvironment.setActiveProfiles(java.lang.String...)
,
ConfigurableEnvironment.setDefaultProfiles(java.lang.String...)
,
AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME
,
AbstractEnvironment.DEFAULT_PROFILES_PROPERTY_NAME
,
Conditional
,
ActiveProfiles
public abstract String[] value