The BeanFactory factory=new XmlBeanFactory (new ClassPathResource (" spring - test - bean. XML ")); Manually configure a bean in the XML, in the process of the Spring loaded, XML bean will be placed in the beanFactory inside, but on the other through annotations inject beans, but not at this time,
public void xmlbeanFactoryResource () throws IOException {
The BeanFactory factory=new XmlBeanFactory (new ClassPathResource (
"Spring - test - bean. XML"));
//getBeanTest XML injection, have value
GetBeanTest beanTest=(GetBeanTest) factory) getBean (" GetBeanTest ");
BeanTest. BeanTest ();
//personArtServiceimpl @ service into the factory has no value, an error
System. The out. Println (factory) getBean (" personArtServiceimpl "));
}
Do you have any friend can tell me why, when injection is the automatic annotation (ApplicationContext I also is such),
My idea is to start the process of the Spring, a Spring bean in the configuration file is should be the first injection, to scan in accordance with the rules for annotations injection, however, so a few lines of code is, where he was injected annotation bean?
CodePudding user response:
When the servlet init createaplicationcontext load the XML file, he will be destroyed before before loadingCodePudding user response:
ComponentScanBeanDefinitionParser parse method in the class, when scanning class loadingCodePudding user response: