diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java index 8deda89418..6e0de9da54 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java @@ -745,7 +745,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto if (containsBeanDefinition(beanName)) { RootBeanDefinition bd = getMergedLocalBeanDefinition(beanName); // Check raw bean class, e.g. in case of a proxy. - if (bd.hasBeanClass()) { + if (bd.hasBeanClass() && bd.getFactoryMethodName() == null) { Class beanClass = bd.getBeanClass(); if (beanClass != beanType) { MergedAnnotation annotation = diff --git a/spring-context/src/test/java/org/springframework/context/annotation/configuration/BeanMethodQualificationTests.java b/spring-context/src/test/java/org/springframework/context/annotation/configuration/BeanMethodQualificationTests.java index 822f5d1a0e..4fbc1fb2b6 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/configuration/BeanMethodQualificationTests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/configuration/BeanMethodQualificationTests.java @@ -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"); }