// classpath:META-INF/spring/spring-config.xml
private static ApplicationContext buildApplicationContext(String springConfigPath) {
DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
Resource resource = resourceLoader.getResource(springConfigPath);
if (!resource.exists()) {
throw new IllegalArgumentException("Spring config path: " + springConfigPath + " does not exist!");
} else {
return new GenericXmlApplicationContext(new Resource[] {resource});
}
}
本文介绍了一种通过指定配置路径来构建Spring应用上下文的方法。使用DefaultResourceLoader加载资源,并检查资源是否存在,若存在则使用GenericXmlApplicationContext创建应用上下文。
323

被折叠的 条评论
为什么被折叠?



