Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Caused by: java.lang.ClassCastException: org.springframework.web.context.support.ServletContextResource cannot be cast to org.springframework.core.io.WritableResource #734

Closed
sayi65 opened this issue Jun 11, 2018 · 7 comments
Labels
awaiting waiting for something external

Comments

@sayi65
Copy link

sayi65 commented Jun 11, 2018

I referred this URL:
https://docs.spring.io/spring-cloud-gcp/docs/1.0.0.M3/reference/htmlsingle/#_google_cloud_storage

#254 has same error

code:

                   String bucket = "gs://BUCKET-NAME/";

                   filename = UUID.randomUUID().toString() + ".jpg";

                   WritableResource gcs = (WritableResource)
                           context.getResource(bucket + "/" + filename);

                   try (OutputStream os = gcs.getOutputStream()) {
                       os.write(profile.getAvatar().getBytes());
                   } catch (IOException e) {
                       e.printStackTrace();
                   }

application.properties

spring.cloud.gcp.project-id=PROJECT-ID
spring.cloud.gcp.credentials.location=file://*.json
spring.cloud.gcp.storage.credentials.scopes=https://www.googleapis.com/auth/devstorage.read_write

build.gradle

dependencies {
    compile 'org.springframework.cloud:spring-cloud-gcp:1.0.0.M3'
}repositories {
    maven {
        url 'https://repo.spring.io/libs-milestone'
    }
}

ERROR:
java.lang.ClassCastException: org.springframework.web.context.support.ServletContextResource cannot be cast to org.springframework.core.io.WritableResource

@meltsufin
Copy link
Contributor

@sayi65 Thank you for the issue submission!
We have a sample app that is doing something very similar and does not encounter this error.
We can't debug this further unless with can reproduce the issue. Can you please start with our sample, and see it how needs to be modified to cause this error?

@meltsufin meltsufin added the awaiting waiting for something external label Jun 11, 2018
@ChengyuanZhao
Copy link
Contributor

It looks like you're adding an extra slash because the bucket string already has one at the end. (but then again you have a placeholder "BUCKET-NAME" bucket name there, so i don't know if your actual code has this extra slash also)

@sayi65
Copy link
Author

sayi65 commented Jun 12, 2018

@meltsufin
OK thank you for your comment.
i will try that sample app.

@sayi65
Copy link
Author

sayi65 commented Jun 12, 2018

@ChengyuanZhao
thank you for your comment.
i will delete the slash.

@orhan-swe
Copy link

@sayi65 Did you ever manage to resolve the issue?

@meltsufin
Copy link
Contributor

@orhan-swe Are you able to reproduce the issue? If so, can you share some code that we can try?

@orhan-swe
Copy link

Actually I am getting another error so I do not think this is relevant anymore. If I do find it relevant I will post my findings here later.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
awaiting waiting for something external
Development

No branches or pull requests

4 participants