Consistently evaluate defaultCandidate flag on constructors and methods
Closes gh-33762
This commit is contained in:
@@ -195,6 +195,28 @@ class BeanMethodQualificationTests {
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void customWithConstructor() {
|
||||
AnnotationConfigApplicationContext ctx = context(CustomConfig.class, CustomPojoWithConstructor.class);
|
||||
|
||||
CustomPojoWithConstructor pojo = ctx.getBean(CustomPojoWithConstructor.class);
|
||||
assertThat(pojo.plainBean).isNull();
|
||||
assertThat(pojo.testBean.getName()).isEqualTo("interesting");
|
||||
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void customWithMethod() {
|
||||
AnnotationConfigApplicationContext ctx = context(CustomConfig.class, CustomPojoWithMethod.class);
|
||||
|
||||
CustomPojoWithMethod pojo = ctx.getBean(CustomPojoWithMethod.class);
|
||||
assertThat(pojo.plainBean).isNull();
|
||||
assertThat(pojo.testBean.getName()).isEqualTo("interesting");
|
||||
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void beanNamesForAnnotation() {
|
||||
AnnotationConfigApplicationContext ctx = context(StandardConfig.class);
|
||||
@@ -327,6 +349,7 @@ class BeanMethodQualificationTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
static class EffectivePrimaryConfig {
|
||||
|
||||
@@ -346,6 +369,7 @@ class BeanMethodQualificationTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Component @Lazy
|
||||
static class StandardPojo {
|
||||
|
||||
@@ -418,6 +442,35 @@ class BeanMethodQualificationTests {
|
||||
}
|
||||
|
||||
|
||||
@InterestingPojo
|
||||
static class CustomPojoWithConstructor {
|
||||
|
||||
TestBean plainBean;
|
||||
|
||||
TestBean testBean;
|
||||
|
||||
public CustomPojoWithConstructor(Optional<TestBean> plainBean, @InterestingNeed TestBean testBean) {
|
||||
this.plainBean = plainBean.orElse(null);
|
||||
this.testBean = testBean;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@InterestingPojo
|
||||
static class CustomPojoWithMethod {
|
||||
|
||||
TestBean plainBean;
|
||||
|
||||
TestBean testBean;
|
||||
|
||||
@Autowired
|
||||
public void applyDependencies(Optional<TestBean> plainBean, @InterestingNeed TestBean testBean) {
|
||||
this.plainBean = plainBean.orElse(null);
|
||||
this.testBean = testBean;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Qualifier
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface Boring {
|
||||
|
||||
Reference in New Issue
Block a user