-
Notifications
You must be signed in to change notification settings - Fork 38.9k
Closed as not planned
Closed as not planned
Copy link
Labels
for: stackoverflowA question that's better suited to stackoverflow.comA question that's better suited to stackoverflow.com
Description
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")); // truebut 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")); // falseI 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.
Metadata
Metadata
Assignees
Labels
for: stackoverflowA question that's better suited to stackoverflow.comA question that's better suited to stackoverflow.com