0 votes
in Education by (1.7m points)
I'm developing a Spring Boot application in which I'm integrating Amazon S3 service.

This class is my repository to access the S3 bucket :

public class S3FileRepository implements ImageRepository {

private String bucket;

private AmazonS3 s3Client;

private ResourceLoader resourceLoader;

public S3FileRepository(ResourceLoader resourceLoader, AmazonS3 s3Client, String bucket) {

    this.resourceLoader = resourceLoader;

    this.s3Client = s3Client;

    this.bucket = bucket;


private static String toS3Uri(String bucket, String imageName) {

    return String.format("s3://%s/%s", bucket, imageName);



public Resource getImage(String name) {

    return resourceLoader.getResource(S3FileRepository.toS3Uri(this.bucket, name).concat(this.IMAGE_EXTENSION));


using Spring Boot Autoconfiguration as suggested.

So in my pom.xml, among other things, I've











Moreover I've an application.properties done like this:

cloud.aws.credentials.accessKey= (mykey)

cloud.aws.credentials.secretKey= (mysecret)




The problem:

Everything works fine if i compile my project and then I simply run the JAR with java -jar target/myproject.jar, i correctly get the image that I ask for and everything is fine.

Instead if I run the project with the IDE default mvn spring-boot:run when I try to get an image (present in the bucket) an Exception occour saying following:

    ServletContext resource [/s3://mybucket/test.jpeg] cannot be resolved to URL because it does not exist

java.io.FileNotFoundException: ServletContext resource [/s3://mybucket/test.jpeg] cannot be resolved to URL because it does not exist

So what I think is that it throws an Exception because it's like it goes inside the jar to look for something that match s3://mybucket/test.jpeg but I can't get why, and why it happens only running the project with mvn spring-boot:run and not running the jar.

JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by (1.7m points)
You're likely hitting the spring-cloud-aws issue #384 whereupon the spring-boot-devtools dependency, which is activated when you start the application from the IDE, activates a different code path in resource loading.

You can test whether you're hitting this issue by removing the spring-boot-devtools dependency from your pom.xml file, reloading the project in your IDE, and running the same test.