/*
 * Copyright 2002-2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.context.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.core.annotation.AliasFor;

When used as a type-level annotation in conjunction with @Component, @Scope indicates the name of a scope to use for instances of the annotated type.

When used as a method-level annotation in conjunction with @Bean, @Scope indicates the name of a scope to use for the instance returned from the method.

NOTE: @Scope annotations are only introspected on the concrete bean class (for annotated components) or the factory method (for @Bean methods). In contrast to XML bean definitions, there is no notion of bean definition inheritance, and inheritance hierarchies at the class level are irrelevant for metadata purposes.

In this context, scope means the lifecycle of an instance, such as singleton, prototype, and so forth. Scopes provided out of the box in Spring may be referred to using the SCOPE_* constants available in the ConfigurableBeanFactory and WebApplicationContext interfaces.

To register additional custom scopes, see CustomScopeConfigurer.

Author:Mark Fisher, Chris Beams, Sam Brannen
See Also:
Since:2.5
/** * When used as a type-level annotation in conjunction with * {@link org.springframework.stereotype.Component @Component}, * {@code @Scope} indicates the name of a scope to use for instances of * the annotated type. * * <p>When used as a method-level annotation in conjunction with * {@link Bean @Bean}, {@code @Scope} indicates the name of a scope to use * for the instance returned from the method. * * <p><b>NOTE:</b> {@code @Scope} annotations are only introspected on the * concrete bean class (for annotated components) or the factory method * (for {@code @Bean} methods). In contrast to XML bean definitions, * there is no notion of bean definition inheritance, and inheritance * hierarchies at the class level are irrelevant for metadata purposes. * * <p>In this context, <em>scope</em> means the lifecycle of an instance, * such as {@code singleton}, {@code prototype}, and so forth. Scopes * provided out of the box in Spring may be referred to using the * {@code SCOPE_*} constants available in the {@link ConfigurableBeanFactory} * and {@code WebApplicationContext} interfaces. * * <p>To register additional custom scopes, see * {@link org.springframework.beans.factory.config.CustomScopeConfigurer * CustomScopeConfigurer}. * * @author Mark Fisher * @author Chris Beams * @author Sam Brannen * @since 2.5 * @see org.springframework.stereotype.Component * @see org.springframework.context.annotation.Bean */
@Target({ElementType.TYPE, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface Scope {
Alias for scopeName.
See Also:
/** * Alias for {@link #scopeName}. * @see #scopeName */
@AliasFor("scopeName") String value() default "";
Specifies the name of the scope to use for the annotated component/bean.

Defaults to an empty string ("") which implies SCOPE_SINGLETON.

See Also:
Since:4.2
/** * Specifies the name of the scope to use for the annotated component/bean. * <p>Defaults to an empty string ({@code ""}) which implies * {@link ConfigurableBeanFactory#SCOPE_SINGLETON SCOPE_SINGLETON}. * @since 4.2 * @see ConfigurableBeanFactory#SCOPE_PROTOTYPE * @see ConfigurableBeanFactory#SCOPE_SINGLETON * @see org.springframework.web.context.WebApplicationContext#SCOPE_REQUEST * @see org.springframework.web.context.WebApplicationContext#SCOPE_SESSION * @see #value */
@AliasFor("value") String scopeName() default "";
Specifies whether a component should be configured as a scoped proxy and if so, whether the proxy should be interface-based or subclass-based.

Defaults to ScopedProxyMode.DEFAULT, which typically indicates that no scoped proxy should be created unless a different default has been configured at the component-scan instruction level.

Analogous to <aop:scoped-proxy/> support in Spring XML.

See Also:
/** * Specifies whether a component should be configured as a scoped proxy * and if so, whether the proxy should be interface-based or subclass-based. * <p>Defaults to {@link ScopedProxyMode#DEFAULT}, which typically indicates * that no scoped proxy should be created unless a different default * has been configured at the component-scan instruction level. * <p>Analogous to {@code <aop:scoped-proxy/>} support in Spring XML. * @see ScopedProxyMode */
ScopedProxyMode proxyMode() default ScopedProxyMode.DEFAULT; }