我正在阅读这个文档:
http://cloud.spring.io/spring-cloud-aws/spring-cloud-aws.html http://cloud.spring.io/spring-cloud-aws/spring-cloud-aws.html
关于从 Spring 应用程序使用 AWS。我对 S3 特别感兴趣,因此,我设置了应用程序并复制了这段代码以确保设置正常工作:
Resource resource = this.resourceLoader.getResource("s3://myBucket/rootFile.log");
WritableResource writableResource = (WritableResource) resource;
try (OutputStream outputStream = writableResource.getOutputStream()) {
outputStream.write("test".getBytes());
}
但是当我运行它时,我收到此错误:
java.lang.ClassCastException: org.springframework.web.context.support.ServletContextResource cannot be cast to org.springframework.core.io.WritableResource
任何想法有什么问题吗?这是设置问题吗?它看起来不像我,但我对此很陌生。
我不得不删除
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
来自我的依赖。
当包含 devtools 时,在 GenericApplicationContext.getResources() 方法内,它会执行 if 块,但如果没有 devtools,它会调用 super.getResource():
public Resource getResource(String location) {
if (this.resourceLoader != null) {
return this.resourceLoader.getResource(location);
}
return super.getResource(location);
}
这将使用 s3 协议处理程序并为您提供实现 WritableResource 的不同类型的资源。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)