提交 d7a16303 编写于 作者: J Juergen Hoeller

removed getBeansWithAnnotation(Class,boolean,boolean) method from...

removed getBeansWithAnnotation(Class,boolean,boolean) method from ListableBeanFactory; reimplemented getBeansWithAnnotation(Class) to avoid use of getBeanNamesForType(Object.class)
上级 929665d2
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 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.
......@@ -221,24 +221,6 @@ $ * <p>Does not consider any hierarchy this factory may participate in.
Map<String, Object> getBeansWithAnnotation(Class<? extends Annotation> annotationType)
throws BeansException;
/**
* Find all beans whose <code>Class</code> has the supplied {@link java.lang.annotation.Annotation} type.
* @param annotationType the type of annotation to look for
* @return a Map with the matching beans, containing the bean names as
* keys and the corresponding bean instances as values
* @param includeNonSingletons whether to include prototype or scoped beans too
* or just singletons (also applies to FactoryBeans)
* @param allowEagerInit whether to initialize <i>lazy-init singletons</i> and
* <i>objects created by FactoryBeans</i> (or by factory methods with a
* "factory-bean" reference) for the type check. Note that FactoryBeans need to be
* eagerly initialized to determine their type: So be aware that passing in "true"
* for this flag will initialize FactoryBeans and "factory-bean" references.
* @throws BeansException if a bean could not be created
*/
Map<String, Object> getBeansWithAnnotation(
Class<? extends Annotation> annotationType, boolean includeNonSingletons, boolean allowEagerInit)
throws BeansException;
/**
* Find a {@link Annotation} of <code>annotationType</code> on the specified
* bean, traversing its interfaces and super classes if no annotation can be
......
......@@ -26,9 +26,11 @@ import java.lang.reflect.Type;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
......@@ -404,14 +406,11 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
}
public Map<String, Object> getBeansWithAnnotation(Class<? extends Annotation> annotationType) {
return getBeansWithAnnotation(annotationType, true, true);
}
public Map<String, Object> getBeansWithAnnotation(
Class<? extends Annotation> annotationType, boolean includeNonSingletons, boolean allowEagerInit) {
Set<String> beanNames = new LinkedHashSet<String>(getBeanDefinitionCount());
beanNames.addAll(Arrays.asList(getBeanDefinitionNames()));
beanNames.addAll(Arrays.asList(getSingletonNames()));
Map<String, Object> results = new LinkedHashMap<String, Object>();
for (String beanName : getBeanNamesForType(Object.class, includeNonSingletons, allowEagerInit)) {
for (String beanName : beanNames) {
if (findAnnotationOnBean(beanName, annotationType) != null) {
results.put(beanName, getBean(beanName));
}
......
......@@ -258,12 +258,6 @@ public class StaticListableBeanFactory implements ListableBeanFactory {
public Map<String, Object> getBeansWithAnnotation(Class<? extends Annotation> annotationType)
throws BeansException {
return getBeansWithAnnotation(annotationType, true, true);
}
public Map<String, Object> getBeansWithAnnotation(
Class<? extends Annotation> annotationType, boolean includeNonSingletons, boolean allowEagerInit) {
Map<String, Object> results = new LinkedHashMap<String, Object>();
for (String beanName : this.beans.keySet()) {
if (findAnnotationOnBean(beanName, annotationType) != null) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册