Skip to content

Second instance of DynamoDBMapperConfig being created #233

Open
@GynnRickerbyNZPost

Description

@GynnRickerbyNZPost

In updating to 5.1.0, on startup we're now getting:

Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dynamoDBMapper' defined in class path resource [{Propriety class details removed}]: Unsatisfied dependency expressed through method 'dynamoDBMapper' parameter 1; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapperConfig' available: expected single matching bean but found 2: dynamoDBMapperConfig,dynamoDB-DynamoDBMapperConfig

We're creating the DynamoDBMapperConfig as per https://github.com/derjust/spring-data-dynamodb/wiki/Alter-table-name-during-runtime.
Looks like something else is also now creating a DynamoDBMapperConfig.

Should these be created now in a different fashion?

Activity

tiagocpeixoto

tiagocpeixoto commented on Feb 7, 2019

@tiagocpeixoto

@GynnRickerbyNZPost

I had the same problem and I found out that I was configuring another DynamoDBMapperConfig bean.

So I removed this extra bean and the error stopped, remaining only the dynamoDB-DynamoDBMapperConfig.

Best regards,

Tiago Peixoto.

GynnRickerbyNZPost

GynnRickerbyNZPost commented on Feb 7, 2019

@GynnRickerbyNZPost
Author

Yes, but I need to configure the DynamoDBMapperConfig to specify table name overrides.

The dynamoDB-DynamoDBMapperConfig one is being created internally (and seems didn't use to be in previous versions), and there's no obvious new documentation on how to turn it off.

tiagocpeixoto

tiagocpeixoto commented on Feb 10, 2019

@tiagocpeixoto

@GynnRickerbyNZPost

Have you tried to set dynamoDBMapperConfigRef property of @EnableDynamoDBRepositories to point to your custom config?

For exemple (in Kotlin):

@EnableDynamoDBRepositories(dynamoDBMapperConfigRef = "customDynamoDBMapperConfig")
class DynamoDbConfig() {

    @Bean("customDynamoDBMapperConfig")
    fun dynamoDBMapperConfig(): DynamoDBMapperConfig = DynamoDBMapperConfig.DEFAULT
}

GynnRickerbyNZPost

GynnRickerbyNZPost commented on Feb 10, 2019

@GynnRickerbyNZPost
Author

Yes. And works fine in 5.0.4.

@Configuration
@EnableDynamoDBRepositories(dynamoDBMapperConfigRef = "dynamoDBMapperConfig")
public class DynamoDBConfig {

  	@Bean("dynamoDBMapperConfig")
	public DynamoDBMapperConfig dynamoDBMapperConfig(final TableNameOverride tableNameOverrider) {
GynnRickerbyNZPost

GynnRickerbyNZPost commented on Feb 10, 2019

@GynnRickerbyNZPost
Author

A quick looking around the code, it looks like DynamoDBMapperConfigFactory was added in 5.1.0, as a FactoryBean which Spring Boot is picking up.

Unfortunately since I've got it working with 5.0.4 I don't have the spare time (project manager is happy with older version working) to go back and work out the appropriate config to override the FactoryBean to use my own settings.

emckissick

emckissick commented on Feb 12, 2019

@emckissick

I ran into this same problem in Spring Boot, but didn't have to override the factory bean, I just removed the ConfigRef from the @EnabledDynamoDBRepositories annotation. If you have a DynamoDBMapperConfig bean the postProcessAfterInitialization method in the DynamoDBMapperConfigFactory will find it and use it.

Have you tried changing
@EnableDynamoDBRepositories(dynamoDBMapperConfigRef = "dynamoDBMapperConfig")
to just this
@EnableDynamoDBRepositories
If this is the correct intent, the documentation found here Alter table name during runtime may need to be updated.

added a commit that references this issue on Feb 24, 2019

fix: issue derjust#233 (checks if dynamoDBMapperConfigRef is set befo…

tiagocpeixoto

tiagocpeixoto commented on Feb 24, 2019

@tiagocpeixoto

I created a PR. Hope it helps!

Feel free to give me feedback.

added a commit that references this issue on Feb 25, 2019
tiagocpeixoto

tiagocpeixoto commented on Mar 9, 2019

@tiagocpeixoto

I made a new fix related to this issue.

9 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Second instance of DynamoDBMapperConfig being created · Issue #233 · derjust/spring-data-dynamodb