Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用resourceLoader从Spring中的多个文件夹加载资源_Java_Spring - Fatal编程技术网

Java 使用resourceLoader从Spring中的多个文件夹加载资源

Java 使用resourceLoader从Spring中的多个文件夹加载资源,java,spring,Java,Spring,这项质询与另一个职位有关— 我想使用ResourceLoader从两个特定文件夹加载所有文件。我正在尝试使用ResourcePatternUtils 福巴级{ 私有资源加载器 @Autowired public Foobar(ResourceLoader resourceLoader) { this.resourceLoader = resourceLoader; } Resource[] loadResources(String pattern) throws IOException

这项质询与另一个职位有关—

我想使用ResourceLoader从两个特定文件夹加载所有文件。我正在尝试使用ResourcePatternUtils

福巴级{ 私有资源加载器

@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");