Java 使用resourceLoader从Spring中的多个文件夹加载资源
这项质询与另一个职位有关— 我想使用ResourceLoader从两个特定文件夹加载所有文件。我正在尝试使用ResourcePatternUtils 福巴级{ 私有资源加载器Java 使用resourceLoader从Spring中的多个文件夹加载资源,java,spring,Java,Spring,这项质询与另一个职位有关— 我想使用ResourceLoader从两个特定文件夹加载所有文件。我正在尝试使用ResourcePatternUtils 福巴级{ 私有资源加载器 @Autowired public Foobar(ResourceLoader resourceLoader) { this.resourceLoader = resourceLoader; } Resource[] loadResources(String pattern) throws IOException
@Autowired
public Foobar(ResourceLoader resourceLoader) {
this.resourceLoader = resourceLoader;
}
Resource[] loadResources(String pattern) throws IOException {
return ResourcePatternUtils.getResourcePatternResolver(resourceLoader).getResources(pattern);
}
}
但我需要在单个阵列中同时使用这两种资源。我应该使用Java8流之类的东西来连接它们吗?这可以通过org.springframework.core.io.support.ResourcePatternResolver#getResources接口实现,在该接口中,您可以将路径作为参数传递
resourcePatternResolver.getResources("classpath:folder/*.xml");
实现是在ApplicationContext上的,因此您也可以从该接口访问假设我需要添加来自不同文件夹的资源,在这种情况下,什么语法起作用<代码>类路径:folder1/*.xml:folder2/*.xml?
resourcePatternResolver.getResources("classpath:folder/*.xml");