简体   繁体   中英

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. 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!

Why is PathMatchingResourcePatternResolver called instead of PathMatchingSimpleStorageResourcePatternResolver ?

After researching I found the answer to this. I have to explicitly autowire resourcePatternResolver to be 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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