Skip to content

Commit

Permalink
Add test for @fallback with BeanFactory.getBean(Class)
Browse files Browse the repository at this point in the history
  • Loading branch information
quaff committed Feb 29, 2024
1 parent 4ff0f86 commit 7d37f2a
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@ void primaryVersusFallback(Class<?> configClass) {
ctx.close();
}

/**
* One regular bean along with fallback beans is considered effective primary
*/
@Test
void effectivePrimary() {
AnnotationConfigApplicationContext ctx = context(EffectivePrimaryConfig.class);

TestBean testBean = ctx.getBean(TestBean.class);
assertThat(testBean.getName()).isEqualTo("effective-primary");

ctx.close();
}

@Test
void customWithLazyResolution() {
AnnotationConfigApplicationContext ctx = context(CustomConfig.class, CustomPojo.class);
Expand Down Expand Up @@ -314,6 +327,24 @@ public TestBean testBean2x() {
}
}

@Configuration
static class EffectivePrimaryConfig {

@Bean
public TestBean effectivePrimary() {
return new TestBean("effective-primary");
}

@Bean @Fallback
public TestBean fallback1() {
return new TestBean("fallback1");
}

@Bean @Fallback
public TestBean fallback2() {
return new TestBean("fallback2");
}
}

@Component @Lazy
static class StandardPojo {
Expand Down

0 comments on commit 7d37f2a

Please sign in to comment.