Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Commit

Permalink
Add support of dependsOn
Browse files Browse the repository at this point in the history
Closes gh-1458
  • Loading branch information
snicoll committed Jan 19, 2022
1 parent a6e807d commit 9dc62d5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.springframework.core.AttributeAccessor;
import org.springframework.core.ResolvableType;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

/**
Expand Down Expand Up @@ -205,6 +206,11 @@ private void handleBeanDefinitionMetadata(Builder code) {
if (StringUtils.hasText(scope) && !ConfigurableBeanFactory.SCOPE_SINGLETON.equals(scope)) {
statements.add("$L.setScope($S)", bdVariable, scope);
}
String[] dependsOn = this.beanDefinition.getDependsOn();
if (!ObjectUtils.isEmpty(dependsOn)) {
statements.add("$L.setDependsOn($L)", bdVariable,
this.parameterWriter.writeParameterValue(dependsOn));
}
if (this.beanDefinition.isLazyInit()) {
statements.add("$L.setLazyInit(true)", bdVariable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,15 @@ void writeWithSyntheticFlag() {
" .instanceSupplier(() -> SampleFactory::new).customize((bd) -> bd.setSynthetic(true)).register(beanFactory);");
}

@Test
void writeWithDependsOn() {
BeanDefinition beanDefinition = BeanDefinitionBuilder.rootBeanDefinition(SampleFactory.class, "create")
.addDependsOn("test").getBeanDefinition();
assertThat(beanRegistration(beanDefinition, (code) -> code.add("() -> SampleFactory::new"))).lines()
.containsOnly("BeanDefinitionRegistrar.of(\"test\", SampleFactory.class)",
" .instanceSupplier(() -> SampleFactory::new).customize((bd) -> bd.setDependsOn(new String[] { \"test\" })).register(beanFactory);");
}

@Test
void writeWithMultipleFlags() {
BeanDefinition beanDefinition = BeanDefinitionBuilder.rootBeanDefinition(SampleFactory.class, "create")
Expand Down

0 comments on commit 9dc62d5

Please sign in to comment.