Merge branch '2.1.x'

Closes gh-18878
pull/18883/head
Andy Wilkinson 5 years ago
commit 63dd159935

@ -30,6 +30,7 @@ import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor; import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.core.Ordered;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
/** /**
@ -45,7 +46,7 @@ import org.springframework.util.StringUtils;
* @since 1.3.0 * @since 1.3.0
* @see BeanDefinition#setDependsOn(String[]) * @see BeanDefinition#setDependsOn(String[])
*/ */
public abstract class AbstractDependsOnBeanFactoryPostProcessor implements BeanFactoryPostProcessor { public abstract class AbstractDependsOnBeanFactoryPostProcessor implements BeanFactoryPostProcessor, Ordered {
private final Class<?> beanClass; private final Class<?> beanClass;
@ -114,6 +115,11 @@ public abstract class AbstractDependsOnBeanFactoryPostProcessor implements BeanF
} }
} }
@Override
public int getOrder() {
return 0;
}
private Set<String> getBeanNames(ListableBeanFactory beanFactory) { private Set<String> getBeanNames(ListableBeanFactory beanFactory) {
Set<String> names = getBeanNames(beanFactory, this.beanClass); Set<String> names = getBeanNames(beanFactory, this.beanClass);
if (this.factoryBeanClass != null) { if (this.factoryBeanClass != null) {

@ -73,6 +73,11 @@ class AbstractDependsOnBeanFactoryPostProcessorTests {
} }
} }
@Test
public void postProcessorHasADefaultOrderOfZero() {
assertThat(new FooDependsOnBarTypePostProcessor().getOrder()).isEqualTo(0);
}
private void assertThatFooDependsOnBar(AssertableApplicationContext context) { private void assertThatFooDependsOnBar(AssertableApplicationContext context) {
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory(); ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
assertThat(getBeanDefinition("foo", beanFactory).getDependsOn()).containsExactly("bar", "barFactoryBean"); assertThat(getBeanDefinition("foo", beanFactory).getDependsOn()).containsExactly("bar", "barFactoryBean");

Loading…
Cancel
Save