@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);
}
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.