-
Notifications
You must be signed in to change notification settings - Fork 695
java.lang.ClassCastException while implementing writeGcs() as given example in https://github.com/spring-cloud/spring-cloud-gcp/blob/master/spring-cloud-gcp-examples/spring-cloud-gcp-storage-resource-example/src/main/java/com/example/WebController.java #254
Comments
It looks like you're missing the Google Cloud Storage Spring Boot Starter dependency and the Does your
The reason we have to cast is because |
Already added the mentioned dependency in pom.xml. Also checked library exist in project or not . |
Can you share a complete example that reproduces this? Maybe change our example to match your setup. |
@pankajnd20 could i trouble you to check my example here? Also, some lab instructions I used: Cheers, |
Also, in your example you don't seem to be writing to the resource. |
Please reopen if you are still seeing this issue. |
Hi all, this issue is still occurring |
@saurabhguptasg when you run the code sample, is the resource created as |
i get the same issue. error: |
There is a working Storage code sample in https://github.com/spring-cloud/spring-cloud-gcp/tree/master/spring-cloud-gcp-samples/spring-cloud-gcp-storage-resource-sample. Would you mind trying it and then adapting to reproduce the issue you're seeing? Please let us know when you were able to do so. |
@joaoandremartins |
error description :
java.lang.ClassCastException: org.springframework.web.context.support.ServletContextResource cannot be cast to org.springframework.core.io.WritableResource
error line :
try (OutputStream os = ((WritableResource) this.gcsFile).getOutputStream())
full code :
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.core.io.WritableResource;
@value("gs://mybucketname/my-file.txt")
private Resource gcsFile;
public String readGcsFile() throws IOException {
return StreamUtils.copyToString(
this.gcsFile.getInputStream(),
Charset.defaultCharset()) + "\n";
}
why it's casting super class to sub class in the example ?
The text was updated successfully, but these errors were encountered: