1. 程式人生 > >Spring載入ApplicationContext方式

Spring載入ApplicationContext方式

1.ApplicationContext 應用上下文,載入Spring 框架配置檔案

載入classpath: new ClassPathXmlApplicationContext("applicationContext.xml");
載入磁碟路徑new FileSystemXmlApplicationContext("applicationContext.xml");

2.使用多個XML配置檔案

 (1)可以在建立ApplicationContext物件時傳入多個配置檔案
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("beans1.xml", "beans2.xml");

 (2)
可以在配置檔案中通過<import>引入其他配置檔案
<import resource="classpath:bean2.xml"/>