Scope.java 2.3 KB
Newer Older
A
Arjen Poutsma 已提交
1
/*
2
 * Copyright 2002-2009 the original author or authors.
A
Arjen Poutsma 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 *
 * 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.BeanDefinition;
C
Chris Beams 已提交
26
import org.springframework.stereotype.Component;
A
Arjen Poutsma 已提交
27 28

/**
C
Chris Beams 已提交
29 30 31 32 33 34 35
 * When used as a type-level annotation in conjunction with the {@link Component}
 * annotation, 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 the
 * {@link Bean} annotation, indicates the name of a scope to use for
 * the instance returned from the method.
A
Arjen Poutsma 已提交
36 37
 *
 * <p>In this context, scope means the lifecycle of an instance, such as
C
Chris Beams 已提交
38
 * {@literal singleton}, {@literal prototype}, and so forth.
A
Arjen Poutsma 已提交
39 40
 * 
 * @author Mark Fisher
41
 * @author Chris Beams
A
Arjen Poutsma 已提交
42
 * @since 2.5
C
Chris Beams 已提交
43 44 45
 * @see Component
 * @see Bean
 * @see StandardScopes
A
Arjen Poutsma 已提交
46
 */
47
@Target({ElementType.TYPE, ElementType.METHOD})
A
Arjen Poutsma 已提交
48 49 50 51 52
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Scope {

	/**
C
Chris Beams 已提交
53 54 55
	 * Specifies the scope to use for the annotated component/bean.
	 * @return the specified scope
	 * @see StandardScopes
A
Arjen Poutsma 已提交
56 57
	 */
	String value() default BeanDefinition.SCOPE_SINGLETON;
58 59 60 61 62 63 64 65

	/**
	 * 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#NO}, indicating no scoped proxy
	 * should be created.
	 * 
C
Chris Beams 已提交
66
	 * <p>Analogous to {@literal <aop:scoped-proxy/>} support in Spring XML. Valid
67 68 69
	 * only in conjunction with a non-singleton, non-prototype {@link #value()}.
	 */
	ScopedProxyMode proxyMode() default ScopedProxyMode.NO;
C
Chris Beams 已提交
70

A
Arjen Poutsma 已提交
71
}