Browse Source

removed getBeansWithAnnotation(Class,boolean,boolean) method from ListableBeanFactory; reimplemented getBeansWithAnnotation(Class) to avoid use of getBeanNamesForType(Object.class)

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@2641 50f2f4bb-b051-0410-bef5-90022cba6387
pull/1/head
Juergen Hoeller 16 years ago
parent
commit
a7bd975e4c
  1. 20
      org.springframework.beans/src/main/java/org/springframework/beans/factory/ListableBeanFactory.java
  2. 13
      org.springframework.beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java
  3. 6
      org.springframework.beans/src/main/java/org/springframework/beans/factory/support/StaticListableBeanFactory.java

20
org.springframework.beans/src/main/java/org/springframework/beans/factory/ListableBeanFactory.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* 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. @@ -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

13
org.springframework.beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java

@ -26,9 +26,11 @@ import java.lang.reflect.Type; @@ -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 @@ -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));
}

6
org.springframework.beans/src/main/java/org/springframework/beans/factory/support/StaticListableBeanFactory.java

@ -258,12 +258,6 @@ public class StaticListableBeanFactory implements ListableBeanFactory { @@ -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) {

Loading…
Cancel
Save