findAnnotationOnBean only falls back to bean class in case of no factory method

Most importantly, static @Bean methods do not expose their @Configuration class-level annotations anymore, aligned with the behavior for non-static @Bean methods.

Closes gh-28298
This commit is contained in:
Juergen Hoeller
2022-06-14 14:01:38 +02:00
parent 083113d8a4
commit a14650e0dc
2 changed files with 8 additions and 5 deletions

View File

@@ -141,16 +141,17 @@ class BeanMethodQualificationTests {
assertThat(ctx.getBeanNamesForAnnotation(Configuration.class)).isEqualTo(new String[] {"beanMethodQualificationTests.StandardConfig"});
assertThat(ctx.getBeanNamesForAnnotation(Scope.class)).isEqualTo(new String[] {});
assertThat(ctx.getBeanNamesForAnnotation(Lazy.class)).isEqualTo(new String[] {"testBean1"});
assertThat(ctx.getBeanNamesForAnnotation(Boring.class)).isEqualTo(new String[] {"testBean2"});
assertThat(ctx.getBeanNamesForAnnotation(Boring.class)).isEqualTo(new String[] {"beanMethodQualificationTests.StandardConfig", "testBean2"});
ctx.close();
}
@Configuration
@Boring
static class StandardConfig {
@Bean @Qualifier("interesting") @Lazy
public TestBean testBean1() {
public static TestBean testBean1() {
return new TestBean("interesting");
}
@@ -163,10 +164,11 @@ class BeanMethodQualificationTests {
}
@Configuration
@Boring
static class ScopedConfig {
@Bean @Qualifier("interesting") @Scope("prototype")
public TestBean testBean1() {
public static TestBean testBean1() {
return new TestBean("interesting");
}
@@ -179,10 +181,11 @@ class BeanMethodQualificationTests {
}
@Configuration
@Boring
static class ScopedProxyConfig {
@Bean @Qualifier("interesting") @Scope(value="prototype", proxyMode=ScopedProxyMode.TARGET_CLASS)
public TestBean testBean1() {
public static TestBean testBean1() {
return new TestBean("interesting");
}