Add a constructor to S3ProtocolResolver allowing its usage outside of Spring context #1276
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add a constructor to
S3ProtocolResolver
allowing its usage outside of Spring context📢 Type of change
📜 Description
A new constructor was added to
S3ProtocolResolver
allowing setting required fields directly rather than lazily later usingBeanFactory
. But the method withBeanFactory
is still used by default byS3AutoConfiguration
which createsS3ProtocolResolver
through@Import(S3ProtocolResolver.class)
, not through a method with@Bean
annotation.💡 Motivation and Context
In our application we need to fetch some configuration files from S3 before Spring context fully starts, so that properties from S3 will be included in
@ConditionalOnProperty
, etc. We decided to do that inEnvironmentPostProcessor
, we have working proof-of-concept with a copy ofS3ProtocolResolver
from Spring Cloud AWS but it would be best to use originalS3ProtocolResolver
, and a lack of proper constructor is blocking that.We are aware of #161 but we need something lighter.
💚 How did you test it?
S3ProtocolResolverTests
which use the same approach as inS3AutoConfiguration
, i.e.@Import(S3ProtocolResolver.class)
still pass, and the new constructor is not called automatically even if the no-arg one is removed (in such a case there isBeanInstantiationException: Failed to instantiate [io.awspring.cloud.s3.S3ProtocolResolver]: No default constructor found
). That also means that the change is backward compatible and it neither affects the existing code nor change the flow.📝 Checklist
@Testcontainers
on local machine)🔮 Next steps
The new constructor could potentially be used to create a bean in the standard way through
@Bean
method but that would be a breaking change, assuming the no-arg constructor would be removed with that change.