Hello! As the title suggests, i have found a confusing question and look forward to an official answer

testPopulateBean.xml

<context:component-scan base-package="com.my.populateBean"></context:component-scan>
<bean id="b1" class="com.my.populateBean.Book"></bean>
@Component("book")
public class Book {
    public Book() {}
}

Test Case

ApplicationContext ac = new ClassPathXmlApplicationContext("testPopulateBean.xml");
System.out.println(ac.containsBean("book"));  // true

but if the context:component-scan label is located below. Such as

<bean id="b1" class="com.my.populateBean.Book"></bean>
<context:component-scan base-package="com.my.populateBean"></context:component-scan>

Test Case

ApplicationContext ac = new ClassPathXmlApplicationContext("testPopulateBean.xml");
System.out.println(ac.containsBean("book"));  // false

I posted that it was deleted in this place ConfigurationClassParser#processConfigurationClass

 if (configClass.isScanned()) {
      String beanName = configClass.getBeanName();
      if (StringUtils.hasLength(beanName) && this.registry.containsBeanDefinition(beanName)) {
          this.registry.removeBeanDefinition(beanName);
      }
      // An implicitly scanned bean definition should not override an explicit import.
      return;
 }

In my understanding, it is to prevent duplicate imports of beans imported by @ Important, but to cause normal @ Component beans to be deleted. Do you know if my understanding is correct? Is this phenomenon expected?

Thanks.

Comment From: snicoll

Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use the issue tracker only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.