spring: ApplicationContext realization of three classes

* The three common implementation class ApplicationContest 
* ClassPathXmlApplicationContext: it can be configured to load the class file path, the file must be arranged in claim class path, if it is not loaded not
* FileSystemXmlApplicationContext: it can load any disk in the configuration file path (there must be access)
* AnnotationConfigApplicationContext: it is used to read the annotation to create container

* Two interfaces lead to the problem of the core container: 
* ApplicationContext: singleton object apply
* it when building the core container, create a policy target is to take the way to take immediate loading. In other words, as long as one has finished reading the configuration file immediately create a configuration file is an object
multiple cases of Object applicable: * BeanFactory
by way of delay in loading time * it when building the core container, the object used to create a policy. That is to say, when to get the object, and when to really create an object based on the id
1          // 1. Obtaining Core container object 
2          the ApplicationContext AC = new new the ClassPathXmlApplicationContext ( "bean.xml" );
 . 3          // 2. The acquisition Bean object ID 
. 4          IAccountService AS = (IAccountService) ac.getBean ( "AccountService" );
 . 5          // be obtained by strong rotation IAccountDao byte code 
. 6          IAccountDao ac.getBean AD = ( "AccountDao", IAccountDao. class );     
1         Resource resource = new ClassPathResource("bean.xml");
2         BeanFactory factory = new XmlBeanFactory(resource);
3         IAccountService accountService = (IAccountService) factory.getBean("accountService");

 

Guess you like

Origin www.cnblogs.com/flypig666/p/11511498.html
Recommended