FileSystemXmlApplicationContext:可以加载磁盘路径下的配置文件(不常用)
public class Client {
public static void main(String[] args) {
ApplicationContext context =
new FileSystemXmlApplicationContext("C:\\Users\\ghh\\Desktop\\bean.xml");
AccountService service = context.getBean("accountService", AccountService.class);
AccountDao accountDao = context.getBean("accountDao", AccountDao.class);
System.out.println(service);
System.out.println(accountDao);
}
}
ClassPathXmlApplicationContext:可以加载类路径下的配置文件
要求配置文件必须在类路径下面
public class Client {
public static void main(String[] args) {
ApplicationContext context =
new ClassPathXmlApplicationContext("bean.xml");
AccountService service = context.getBean("accountService", AccountService.class);
AccountDao accountDao = context.getBean("accountDao", AccountDao.class);
System.out.println(service);
System.out.println(accountDao);
}
}
AnnotationConfigApplicationContext:读取注解创建容器