2.Interface ApplicationContext 是一個super interface of BeanFactory,並且有其他更多的function在內,所以簡單的說,BeanFactory提供了簡單的一些設定與基本function,而ApplicationContext則是提供了更多,是一個完整的 supertset of BeanFactory.然則!建議使用ApplicationContext.
3.在ioc的控制上主要是以設定的方式進行對應,目前已知的有xml-based , annotation-based等方式
4.範例..
5.初始化一個container:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
ApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"services.xml","daos.xml"});
BeanFactory factory = context;
6.可以用import的方式把config metadata 綁進至另一個config metadata
7.BeanFactory 式可以讓你用來讀取bean definitions,透過以下指令處理
Resource res = new FileSystemResource("beans.xml");
BeanFactory fac = new XmlBeanFactory(res);
8.DI - Dependency Injection,有區分為 constructor injection and setter injection
9.到底該用 constructor or setter based DI ?大部分建議用Setter DI
沒有留言:
張貼留言