-
Notifications
You must be signed in to change notification settings - Fork 375
SimpleStorageResource not resolved in spring-boot 2.1.x #348
Comments
Thanks @JurrianFahner for reporting. This is unfortunately a regression as we have utilized some new Spring features for loading resources (to solve some other bugs). It seems that this does not work with the Web Application context. I will add test cases with a web application context and see how to solve it. In the meantime you could inject a org.springframework.cloud.aws.core.io.s3.SimpleStorageProtocolResolver and use that directly (pass in the location and the application context to the resolve method) |
Well that's not so easy. Because SimpleStorageProtocolResolver needs an S3 client with credentials. So I use RC2 in the meantime until this is fixed. My project is in dev phase, so I have some time. I imagine that it will be fixed soon. |
This makes the S3 resource loader indeed unusable. RC2 does work though. Is there a plan to fix this with 2.0.x ? |
Is this related to #384 ? |
Nope, because I didn't use devtools. So removing devtools wouldn't fix the issue. |
I have used this inline workaround for now Resource resource = resourceLoader.getResource(location);
// workaround for https://github.com/spring-cloud/spring-cloud-aws/issues/348
// TODO: wait the bug to be solved and remove the "if" below
if (!resource.getClass().getName().endsWith("SimpleStorageResource") && resourceLoader instanceof DefaultResourceLoader) {
for (ProtocolResolver protocolResolver : ((DefaultResourceLoader) resourceLoader)
.getProtocolResolvers()) {
if (protocolResolver instanceof SimpleStorageProtocolResolver) {
resource = protocolResolver.resolve(location, resourceLoader);
break;
}
}
} |
@denis111 Thanks! I just started using Spring Cloud AWS and this was very helpful to me. In my project, the same workaround looks like this (in Kotlin):
However, while this works for a My workaround looks like this
but I believe this is caused by the same bug, and should be fixed as well. |
Hi, I've also encountered this issue, but the workaround suggested by @denis111 does not work (same error), and doesn't really address the issue. Any other approaches that have worked, or any news on when this may be fixed? |
@cjdudleybw Did you register a |
I can confirm that in Greenwich.RELEASE the problem is fixed, and SimpleStorageResource is working. But that's only true for spring-boot 2.1.x |
Hello,
Since this was reopened - can we assume that Greenwich.SR1 is not/not completely resolving this issue? |
Works fine for me with Spring Boot 2.1.x... |
I am experiencing the same issue of the s3 protocol not resolving and getting a FileNotFoundException. Using Spring Boot starter 2.1.3-RELEASE and Spring Cloud Greenwich.RELEASE. Will try workaround by @denis111 and post back if it works. |
Update # 2: Got it working with a different workaround. Still on Greenwich.RELEASE and Boot 2.1.3.RELEASE. Despite the s3: protocol, my resource is a When I try to wire in
I have to manually create SimpleStorageProtocolResolver simpleStorageProtocolResolver = new SimpleStorageProtocolResolver(amazonS3); AWS Context XML: POM excerpt: <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/>
</parent>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-aws-context</artifactId>
</dependency>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Greenwich.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement> Hopefully a fix will be found soon! |
I also have this issue with Spring Boot 2.1.5 and Greenwich. @amgapuz do you have a more detailed example on how to configure the |
I have upgraded to Spring Boot 2.1.5 and Spring Cloud Context 2.1.1 and I found that this is working now if I remove Spring Boot Devtools from the classpath. This might explain why it's working for @JurrianFahner now, but not for others. It seems like something has been fixed, but this issue is also caused by #384. This problem has also been reported with Spring Boot, but has not been resolved yet: spring-projects/spring-boot#9331. When autowiring The When I try to add a S3 resource location in
|
@darioseidl We should maybe list projects which aren't working with specific combinations. I've changed the title, because the issue applies now to other situations than finley only. |
I had to manually create a SimpleStorageProtocolResolver by auto-wiring in AmazonS3 to my bean and passing it in to the constructor: @Autowired
private AmazonS3 amazonS3;
// Spring Core IO ResourceLoader - AWS context XML sets this correctly
// If you are looking to set and configure the AWS context in code, I have no example for that
@Autowired
private ResourceLoader resourceLoader;
public void myMethodToFetchFromS3() {
SimpleStorageProtocolResolver simpleStorageProtocolResolver = new SimpleStorageProtocolResolver(amazonS3);
Resource aResource = resourceLoader.getResource("s3://bucket/path/to/resource");
// The workaround
if (!aResource.getClass().getName().endsWith("SimpleStorageResource") &&
resourceLoader instanceof DefaultResourceLoader) {
aResource = simpleStorageProtocolResolver.resolve("s3://bucket/path/to/resource", resourceLoader);
}
} Hope that helps. |
Good to know - about to upgrade to spring boot 2.2.x |
@denis111 and @annagapuz It is nice that you both are testing spring cloud aws on spring-boot 2.2.x. But were you also aware that spring-cloud is not yet ready for spring boot 2.2.x (when you reported the bugs)? I can't figure it out from your feedback, which spring-cloud version you used.
So in order to get spring-boot 2.2.x working with spring cloud, you'll need Hoxton.RELEASE. Can you please let us know whether the problem persists when you upgrade to Hoxton.RELEASE? |
This seems to be fixed with Spring Boot 2.2.1 and Spring Cloud AWS 2.2.0 for me. The bug, where the SimpleStorageProtocolResolver would not be resolved when DevTools was on the classpath, has been fixed in Spring Boot and Spring Framework: spring-projects/spring-boot#17214 I have a simple test here: https://github.com/darioseidl/s3demo. With and without Spring Boot Devtools on the classpath, the SimpleStorageResource is resolved correctly now. |
@JurrianFahner yes, I was on Greenwich and can confirm that with Hoxton I don't need the workaround. |
No, It just happend to me again running with Gradle's bootRun java.io.FileNotFoundException: Could not open ServletContext resource [/s3://... |
@JurrianFahner I saw the error with Boot 2.1.3-RELEASE and Cloud Greenwich.RELEASE. I have not tested with 2.2.X + Hoxton. Will be doing an upgrade soon though. |
Ran into the issue with Boot 2.2.2.RELEASE + Cloud Hoxton.SR1 |
I am not able to reproduce this bug with Spring Boot 2.3 and Spring Cloud AWS 2.2.2. If you are still facing this issue please comment ideally with a link to github repo that reproduces the bug. |
@maciejwalkowiak here is a repo with the latest versions, where When it's not available, I have this exception:
|
Thanks @PavelPolyakov! We will look into it. |
Resolve AmazonS3 client when the first resource is loaded - leaving time for custom AmazonS3 bean to be created. Fixes spring-atticgh-640 Fixes spring-atticgh-641 Introduced when fixing spring-atticgh-348.
Resolve AmazonS3 client when the first resource is loaded - leaving time for custom AmazonS3 bean to be created. Fixes spring-attic#640 Fixes spring-attic#641 Introduced when fixing spring-attic#348.
Resolve AmazonS3 client when the first resource is loaded - leaving time for custom AmazonS3 bean to be created. Fixes spring-attic/spring-cloud-aws#640 Fixes spring-attic/spring-cloud-aws#641 Introduced when fixing spring-attic/spring-cloud-aws#348.
In the documentation this snippet can be found:
This works in Finchley.RC2 as expected. But when I run the same code with only spring cloud updated to Finchley.RELEASE, I get the following class cast exception:
org.springframework.web.context.support.ServletContextResource cannot be cast to org.springframework.core.io.WritableResource
In my debugger I see that the Resource should be an instance of a SimpleStorageResource, instead it is an instance of a ServletContextResource.
That is caused by the resourceLoader which shoud be a org.springframework.cloud.aws.core.io.s3.PathMatchingSimpleStorageResourcePatternResolver, instead it is an instance of a AnnotationConfigServletWebServerApplicationContext.
I use spring-boot 2.0.3
The text was updated successfully, but these errors were encountered: