Skip to content

Commit 3b7ca7e

Browse files
committed
Further tests for getBeanNamesForType(ResolvableType)
Issue: SPR-14097 (cherry picked from commit edea66a)
1 parent dc6e512 commit 3b7ca7e

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/ListableBeanFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -109,6 +109,7 @@ public interface ListableBeanFactory extends BeanFactory {
109109
* @return the names of beans (or objects created by FactoryBeans) matching
110110
* the given object type (including subclasses), or an empty array if none
111111
* @since 4.2
112+
* @see #isTypeMatch(String, ResolvableType)
112113
* @see FactoryBean#getObjectType
113114
* @see BeanFactoryUtils#beanNamesForTypeIncludingAncestors(ListableBeanFactory, ResolvableType)
114115
*/

spring-beans/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessorTests.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.springframework.beans.factory.support.GenericBeanDefinition;
4646
import org.springframework.beans.factory.support.RootBeanDefinition;
4747
import org.springframework.core.Ordered;
48+
import org.springframework.core.ResolvableType;
4849
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
4950
import org.springframework.core.annotation.Order;
5051
import org.springframework.tests.sample.beans.ITestBean;
@@ -1397,6 +1398,8 @@ public void testGenericsBasedFieldInjectionWithSimpleMatch() {
13971398
assertSame(1, bean.stringRepositoryMap.size());
13981399
assertSame(repo, bean.repositoryMap.get("repo"));
13991400
assertSame(repo, bean.stringRepositoryMap.get("repo"));
1401+
1402+
assertArrayEquals(new String[] {"repo"}, bf.getBeanNamesForType(ResolvableType.forClassWithGenerics(Repository.class, String.class)));
14001403
}
14011404

14021405
@Test
@@ -1777,6 +1780,9 @@ public void testGenericsBasedInjectionIntoTypeVariableSelectingBestMatch() {
17771780
GenericInterface1Impl bean1 = (GenericInterface1Impl) bf.getBean("bean1");
17781781
GenericInterface2Impl bean2 = (GenericInterface2Impl) bf.getBean("bean2");
17791782
assertSame(bean2, bean1.gi2);
1783+
1784+
assertArrayEquals(new String[] {"bean1"}, bf.getBeanNamesForType(ResolvableType.forClassWithGenerics(GenericInterface1.class, String.class)));
1785+
assertArrayEquals(new String[] {"bean2"}, bf.getBeanNamesForType(ResolvableType.forClassWithGenerics(GenericInterface2.class, String.class)));
17801786
}
17811787

17821788
@Test
@@ -2765,7 +2771,7 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
27652771

27662772
public interface GenericInterface1<T> {
27672773

2768-
public String doSomethingGeneric(T o);
2774+
String doSomethingGeneric(T o);
27692775
}
27702776

27712777

0 commit comments

Comments
 (0)