简体   繁体   English

ResourcePatternResolver 未列出 s3 中文件夹中的文件

[英]ResourcePatternResolver Not listing files from a folder in s3

@Autowired
private ResourcePatternResolver resourcePatternResolver;

String s3path = req.s3Folder+"/key1/key123/*.gz";

Resource[] allTxtFilesInFolder  = resourcePatternResolver.getResources(s3path);

I am trying to read file from s3 using spring-cloud-starter-aws.我正在尝试使用 spring-cloud-starter-aws 从 s3 读取文件。 Anyhow it works well when filename is fully specified and doesn't work with wildcards.无论如何,当完全指定文件名并且不适用于通配符时,它运行良好。

This is what I see in log这是我在日志中看到的

INFO [ main] [.isPathMatchingResourcePatternResolver] : Failed to resolve Amazon s3 resource [bucket='bucketname' and object='2l6hpfhfryz8422qr8nxy8x0a2-0/key1/key123'] in the file system: java.lang.UnsupportedOperationException: Amazon S3 resource can not be resolved to java.io.File objects.Use getInputStream() to retrieve the contents of the object!信息 [main] [.isPathMatchingResourcePatternResolver]:无法解析文件系统中的 Amazon s3 资源 [bucket='bucketname' and object='2l6hpfhfryz8422qr8nxy8x0a2-0/key1/key123']:java.lang.UnsupportedOperationException:Amazon S3 资源不能被解析为 java.io.File 对象。使用 getInputStream() 来检索对象的内容!

Why is PathMatchingResourcePatternResolver called instead of PathMatchingSimpleStorageResourcePatternResolver ?为什么调用PathMatchingResourcePatternResolver而不是PathMatchingSimpleStorageResourcePatternResolver

After researching I found the answer to this.经过研究,我找到了答案。 I have to explicitly autowire resourcePatternResolver to be PathMatchingSimpleStorageResourcePatternResolver我必须明确自动装配 resourcePatternResolver 为 PathMatchingSimpleStorageResourcePatternResolver

private ResourcePatternResolver resourcePatternResolver;

    @Autowired
    public void setupResolver(ApplicationContext applicationContext, AmazonS3 amazonS3){
        this.resourcePatternResolver = new PathMatchingSimpleStorageResourcePatternResolver(amazonS3, applicationContext);
    }

Reference - https://cloud.spring.io/spring-cloud-static/spring-cloud-aws/2.0.0.RELEASE/multi/multi__resource_handling.html参考 - https://cloud.spring.io/spring-cloud-static/spring-cloud-aws/2.0.0.RELEASE/multi/multi__resource_handling.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM