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

  1. 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

Most upvoted comments

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)

ext {
    springDataVersion = 'Lovelace-SR5'
}
buildscript {
    repositories {
        mavenCentral()
        jcenter()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.3.RELEASE")
        classpath "io.spring.gradle:dependency-management-plugin:1.0.6.RELEASE"
    }
}

apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

dependencyManagement {
    imports {
        mavenBom "org.springframework.data:spring-data-releasetrain:${springDataVersion}"
    }
}

dependencies {
    implementation  "org.springframework.boot:spring-boot-starter-web"
    implementation  group: 'com.github.derjust', name: 'spring-data-dynamodb', version: '5.1.0'
    implementation  'com.amazonaws:aws-java-sdk-dynamodb:1.11.497'
}

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’:

    @Primary
    @Bean(name = "dynamoDB-DynamoDBMapper")
    public DynamoDBMapperFactory dynamoDBMapperFactory() {
        return new DynamoDBMapperFactory(amazonDynamoDB(), dynamoDBMapperConfig());
    }

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

    @Bean
    public AmazonDynamoDB amazonDynamoDB()
    {
        Region region = Regions.getCurrentRegion();
        if(region == null) {
            region = RegionUtils.getRegion(this.region); // This is brought in from a prop file, do it however you want
        }
        return AmazonDynamoDBClientBuilder.standard().withRegion(region.getName()).build();
    }

    @Bean
    @Primary
    public DynamoDBMapper dynamoDBMapper(AmazonDynamoDBClient amazonDynamoDBClient, DynamoDBMapperConfig dynamoDBMapperConfig)
    {
        return new DynamoDBMapper(amazonDynamoDBClient, dynamoDBMapperConfig);
    }

    @Bean
    public DynamoDBMapperConfig dynamoDBMapperConfig() {
        DynamoDBMapperConfig.Builder builder = new DynamoDBMapperConfig.Builder();
        builder.setPaginationLoadingStrategy(DynamoDBMapperConfig.PaginationLoadingStrategy.LAZY_LOADING);
        builder.setTypeConverterFactory(DynamoDBTypeConverterFactory.standard());
        return builder.build();
    }

    @Bean
    public DynamoDB dynamoDB(AmazonDynamoDB amazonDynamoDB)
    {
        return new DynamoDB(amazonDynamoDB);
    }