Add support to define TableSchema as part of Spring context and inject it into DefaultDynamoDbTableSchemaResolver #674
Labels
component: dynamodb
DynamoDB integration related issue
type: enhancement
Smaller enhancement in existing integration
Milestone
Uh oh!
There was an error while loading. Please reload this page.
Type: Feature
Is your feature request related to a problem? Please describe.
When I'm trying to use
io.awspring.cloud:spring-cloud-aws-starter-dynamodb
with GraalVM native-image, the application fails at runtime during TableSchema creation:spring-cloud-aws/spring-cloud-aws-dynamodb/src/main/java/io/awspring/cloud/dynamodb/DefaultDynamoDbTableSchemaResolver.java
Line 32 in 69ad838
It fails due to the fact that AWS SDK trying to generate a class at runtime, that is not supported by native-image (Related issue: oracle/graal#3386)
Stacktrace example:
Describe the solution you'd like
Since the current implementation of the TableSchema generation is not working with native-image (and a workaround for that would be to use StaticTableSchema and to simplify usage of it as a part of the Spring ecosystem I'd recommend to let developers define beans of type
software.amazon.awssdk.enhanced.dynamodb.TableSchema
, which can be used to prefill the cache inDefaultDynamoDbTableSchemaResolver
Describe alternatives you've considered
As an alternative solution without any changes in the framework, I'd have to implement
DefaultDynamoDbTableSchemaResolver
to do my own TableSchema management and add that class to the Spring Context.Additional context
The solution seems to be pretty simple. A pseudo-code example:
Add a method to prefill the cache in DefaultDynamoDbTableSchemaResolver (this method can be invoked from the autoconfiguration)
And finally, in
DynamoDbAutoConfiguration
we can inject a list of TableSchema beans and prefill the cache for theDynamoDbTableSchemaResolver
. (note the initial entity's class can be retrieved fromTableSchema.itemType().rawClass()
In this way, the current behavior of the DynamoDbTableSchemaResolver is not changed (i.e. for classes that derive their schema using
TableSchema.fromBean
), but also it allows developers to define their schema by themselves.If that solution is feasible I can implement it
The text was updated successfully, but these errors were encountered: