support scope meta-annotations on factory methods as well

This commit is contained in:
Juergen Hoeller
2009-07-21 14:23:25 +00:00
parent 54285ea57c
commit ec1f0e6211
5 changed files with 41 additions and 31 deletions

View File

@@ -63,7 +63,7 @@ import org.springframework.beans.factory.annotation.Autowire;
* @see Primary
* @see org.springframework.context.annotation.Scope
*/
@Target(ElementType.METHOD)
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Bean {

View File

@@ -182,8 +182,8 @@ class ConfigurationClassBeanDefinitionReader {
// consider scoping
ScopedProxyMode proxyMode = ScopedProxyMode.NO;
if (metadata.hasAnnotation(Scope.class.getName())) {
Map<String, Object> scopeAttributes = metadata.getAnnotationAttributes(Scope.class.getName());
Map<String, Object> scopeAttributes = metadata.getAnnotationAttributes(Scope.class.getName());
if (scopeAttributes != null) {
beanDef.setScope((String) scopeAttributes.get("value"));
proxyMode = (ScopedProxyMode) scopeAttributes.get("proxyMode");
if (proxyMode == ScopedProxyMode.DEFAULT) {
@@ -195,7 +195,7 @@ class ConfigurationClassBeanDefinitionReader {
BeanDefinition beanDefToRegister = beanDef;
if (proxyMode != ScopedProxyMode.NO) {
BeanDefinitionHolder proxyDef = ScopedProxyCreator.createScopedProxy(
new BeanDefinitionHolder(beanDef, beanName), registry, proxyMode == ScopedProxyMode.TARGET_CLASS);
new BeanDefinitionHolder(beanDef, beanName), this.registry, proxyMode == ScopedProxyMode.TARGET_CLASS);
beanDefToRegister = proxyDef.getBeanDefinition();
}

View File

@@ -72,7 +72,7 @@ class ConfigurationClassEnhancer {
// handling a @Bean-annotated method; otherwise, return index of the NoOp callback.
callbackFilter = new CallbackFilter() {
public int accept(Method candidateMethod) {
return (AnnotationUtils.findAnnotation(candidateMethod, Bean.class) != null) ? 0 : 1;
return (AnnotationUtils.findAnnotation(candidateMethod, Bean.class) != null ? 0 : 1);
}
};
}
@@ -149,8 +149,8 @@ class ConfigurationClassEnhancer {
String beanName = method.getName();
// check to see if the user has explicitly set the bean name
Bean bean = method.getAnnotation(Bean.class);
if(bean != null && bean.name().length > 0) {
Bean bean = AnnotationUtils.findAnnotation(method, Bean.class);
if (bean != null && bean.name().length > 0) {
beanName = bean.name()[0];
}

View File

@@ -57,10 +57,9 @@ public @interface Scope {
/**
* 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.
* <p>Analogous to {@literal <aop:scoped-proxy/>} support in Spring XML. Valid
* only in conjunction with a non-singleton, non-prototype {@link #value()}.
* <p>Defaults to {@link ScopedProxyMode#NO}, indicating that no scoped
* proxy should be created.
* <p>Analogous to {@literal <aop:scoped-proxy/>} support in Spring XML.
*/
ScopedProxyMode proxyMode() default ScopedProxyMode.DEFAULT;