+-

此问题与另一个stackoverflow帖子相关- How to load all files of a folder to a list of Resources in Spring?
我想使用ResourceLoader从两个特定的文件夹中加载所有文件.我正在尝试使用ResourcePatternUtils.
Foobar类{
私有ResourceLoader resourceLoader;
@Autowired
public Foobar(ResourceLoader resourceLoader) {
this.resourceLoader = resourceLoader;
}
Resource[] loadResources(String pattern) throws IOException {
return ResourcePatternUtils.getResourcePatternResolver(resourceLoader).getResources(pattern);
}
}
Resource[] resources1 = foobar.loadResources("classpath*:../../folder1/*.txt");
Resource[] resources2 = foobar.loadResources("classpath*:../../folder2/*.txt");
但是我需要两个资源都放在一个数组中.我应该使用Java8流之类的东西来串联它们吗?
最佳答案
这可以通过org.springframework.core.io.support.ResourcePatternResolver#getResources接口实现,您可以在其中传递路径作为参数.
resourcePatternResolver.getResources("classpath:folder/*.xml");
实现在ApplicationContext上,因此您也可以从此接口访问
点击查看更多相关文章
转载注明原文:java-使用resourceLoader在Spring中从多个文件夹加载资源 - 乐贴网