derjust / spring-data-dynamodb

This module deals with enhanced support for a data access layer built on AWS DynamoDB.
https://derjust.github.io/spring-data-dynamodb/
Apache License 2.0
403 stars 141 forks source link

Multiple DynamoDBMapperConfig beans and dynamoDBMapperConfigRef wiring issue #257

Open gerrytan opened 5 years ago

gerrytan commented 5 years ago

We have a requirement to inject the table name at runtime, hence in version 4.5.0 we injected multiple DynamoDBMapperConfig, one per table, with a table name override.

For each table, we have a configuration bean with following annotation:

@Configuration
@EnableDynamoDBRepositories(
        dynamoDBMapperConfigRef = "redacted*DynamoDBMapperConfig",
        basePackageClasses = {*Redacted*Repository.class}
)

When upgrading to 5.1.0, application fail to start due to wiring issue

Expected Behavior

Application can start same as version 4.5.0

Actual Behavior

Application fail to start with following error

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 1 of constructor in org.socialsignin.spring.data.dynamodb.repository.config.DynamoDBMapperFactory required a single bean, but 4 were found:
    - *redacted*DynamoDBMapperConfig: defined by method '*redacted*DynamoDBMapperConfig' in class path resource [*redacted*/*redacted*/*redacted*/*redacted*/dynamodb/*Redacted*DynamoDBConfig.class]
    - dynamoDB-DynamoDBMapperConfig: defined in null
    - *redacted*DynamoDBMapperConfig: defined by method '*redacted*DynamoDBMapperConfig' in class path resource [*redacted*/*redacted*/*redacted*/*redacted*/*redacted*/*redacted*/*Redacted*DynamoDBConfig.class]
    - *redacted*DynamoDBMapperConfig: defined by method '*redacted*DynamoDBMapperConfig' in class path resource [*redacted*/*redacted*/*redacted*/*redacted*/*redacted*/*redacted*/*redacted*DynamoDBConfig.class]

Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

Steps to Reproduce the Problem

  1. Setup 2 or more repositories, each with its own dynamoDBMapperConfigRef
  2. Start spring boot

Specifications

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.

zorrofox commented 5 years ago

I have the same issue on 2.1.6.RELEASE Spring Data version, and I backward the Spring-Data-DynamoDB version to 5.0.4 to workaround. Anyone have work on 5.1.0 version on Spring Data version 2.1 above?

xmeng1 commented 5 years ago

same issue

thanders commented 5 years ago

I have the same issue with : <artifactId>spring-data-dynamodb</artifactId> <version>5.1.0</version>

<groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.0.RELEASE</version>

I tried using previous versions of each and that doesn't seem to fix it. Does anyone know about a workaround?

YYSAM commented 4 years ago

me too, I have to rollback again... hope someone can fix this issue.

RaghuJ commented 3 years ago

what's the resolution here?