Skip to content

Commit

Permalink
Polish contribution
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Jun 14, 2022
1 parent 0ce9516 commit eeac150
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 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.
Expand Down Expand Up @@ -585,8 +585,9 @@ private String[] doGetBeanNamesForType(ResolvableType type, boolean includeNonSi
if (!matchFound) {
// In case of FactoryBean, try to match FactoryBean instance itself next.
beanName = FACTORY_BEAN_PREFIX + beanName;
matchFound = (includeNonSingletons || isSingleton(beanName, mbd, dbd)) && isTypeMatch(beanName, type, allowFactoryBeanInit);

if (includeNonSingletons || isSingleton(beanName, mbd, dbd)) {
matchFound = isTypeMatch(beanName, type, allowFactoryBeanInit);
}
}
}
if (matchFound) {
Expand Down
Expand Up @@ -1859,6 +1859,22 @@ void getBeanNamesForTypeAfterFactoryBeanCreation() {
assertBeanNamesForType(FactoryBean.class, false, false, "&factoryBean");
}

@Test // gh-28616
void getBeanNamesForTypeWithPrototypeScopedFactoryBean() {
FactoryBeanThatShouldntBeCalled.instantiated = false;
RootBeanDefinition beanDefinition = new RootBeanDefinition(FactoryBeanThatShouldntBeCalled.class);
beanDefinition.setScope(BeanDefinition.SCOPE_PROTOTYPE);
lbf.registerBeanDefinition("factoryBean", beanDefinition);
assertThat(FactoryBeanThatShouldntBeCalled.instantiated).isFalse();
assertThat(lbf.containsSingleton("factoryBean")).isFalse();

// We should not find any beans of the following types if the FactoryBean itself is prototype-scoped.
assertBeanNamesForType(Runnable.class, false, false);
assertBeanNamesForType(Callable.class, false, false);
assertBeanNamesForType(RepositoryFactoryInformation.class, false, false);
assertBeanNamesForType(FactoryBean.class, false, false);
}

/**
* Verifies that a dependency on a {@link FactoryBean} can <strong>not</strong>
* be autowired <em>by name</em>, as &amp; is an illegal character in
Expand Down

0 comments on commit eeac150

Please sign in to comment.