spring-data-dynamodb: Spring 2.1.2 bean creation exception
Expected Behavior
Setup dynamo db
Actual Behavior
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dynamoDB-DynamoDBMapper': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.socialsignin.spring.data.dynamodb.repository.config.DynamoDBMapperFactory]: No default constructor found; nested exception is java.lang.NoSuchMethodException: org.socialsignin.spring.data.dynamodb.repository.config.DynamoDBMapperFactory.<init>()
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1270)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1164)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getSingletonFactoryBeanForTypeCheck(AbstractAutowireCapableBeanFactory.java:974)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:848)
at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:574)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:514)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:477)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:471)
at org.springframework.boot.devtools.autoconfigure.DevToolsDataSourceAutoConfiguration$DevToolsDataSourceCondition.getMatchOutcome(DevToolsDataSourceAutoConfiguration.java:164)
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47)
... 42 more
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.socialsignin.spring.data.dynamodb.repository.config.DynamoDBMapperFactory]: No default constructor found; nested exception is java.lang.NoSuchMethodException: org.socialsignin.spring.data.dynamodb.repository.config.DynamoDBMapperFactory.<init>()
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:83)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1262)
... 51 more
Caused by: java.lang.NoSuchMethodException: org.socialsignin.spring.data.dynamodb.repository.config.DynamoDBMapperFactory.<init>()
at java.base/java.lang.Class.getConstructor0(Class.java:3350)
at java.base/java.lang.Class.getDeclaredConstructor(Class.java:2554)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:78)
... 52 more
Steps to Reproduce the Problem
- Start spring Boot app or run It test
Specifications
- Spring Data DynamoDB Version: 5.1.0
- Spring Data Version: 2.1.0
- AWS SDK Version: 1.11.490
- Java Version: 11
- Platform Details: Spring Boot 2.1.2 RELEASE
All those information are logged by org.socialsignin.spring.data.dynamodb.repository.support.DynamoDBRepositoryFactory
on INFO
level on startup.
Or use java -version
and mvn dependency:tree | grep -E 'spring|aws'
to provide those version numbers.
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 9
- Comments: 27
I have Spring Boot 2.1.3 running on 5.1.0 just fine here is come of the config make sure you using the BOM for Spring Data and not hardcoding dependencies versions, Note that this will move you to the Spring Data 2.1.x release train (Lovelace)
Work’s great here
By reason of project requirements I can’t change version of Spring Boot and also should support ddl auto for all entities (only version 5.1.0 supports this feature ). I’ve fixed this problem by the following workaround , enabling override the spring beans(be careful with it!!!) you should define @Primary beans:
spring.main.allow-bean-definition-overriding=true
Then in my DynamoDBConfiguration class override DynamoDBMapperFactory bean with allowed constructor and set as primary bean for name ‘dynamoDB-DynamoDBMapper’:
Ok, I got it working with the fix. Turns out spring-data-redis was messing stuff up. I had it configured to use a specific version. Started working when I removed the version so it would use the mavenBom
Also you do have to setup your DynamoMapper, here is a snippet