【问题标题】:ResourcePatternResolver Not listing files from a folder in s3ResourcePatternResolver 未列出 s3 中文件夹中的文件
【发布时间】:2019-12-12 23:12:38
【问题描述】:
@Autowired
private ResourcePatternResolver resourcePatternResolver;

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

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

我正在尝试使用 spring-cloud-starter-aws 从 s3 读取文件。无论如何,当完全指定文件名并且不适用于通配符时,它运行良好。

这是我在日志中看到的

INFO [主] [.i.s.PathMatchingResourcePatternResolver]: 无法解析 Amazon s3 资源 [bucket='bucketname' 和 object='2l6hpfhfryz8422qr8nxy8x0a2-0/key1/key123'] 在文件系统中: java.lang.UnsupportedOperationException: Amazon S3 资源不能 解析为 java.io.File 对象。使用 getInputStream() 检索 对象的内容!

为什么叫PathMatchingResourcePatternResolver 而不是PathMatchingSimpleStorageResourcePatternResolver

【问题讨论】:

    标签: java amazon-web-services spring-boot amazon-s3


    【解决方案1】:

    经过研究,我找到了答案。我必须明确地将 resourcePatternResolver 自动连接为 PathMatchingSimpleStorageResourcePatternResolver

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-26
      • 1970-01-01
      • 2018-04-19
      • 2014-07-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-29
      • 1970-01-01
      相关资源
      最近更新 更多