Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use table name prefix with spring boot #5

Closed
dinoo333 opened this issue Feb 13, 2019 · 1 comment
Closed

Cannot use table name prefix with spring boot #5

dinoo333 opened this issue Feb 13, 2019 · 1 comment

Comments

@dinoo333
Copy link

dinoo333 commented Feb 13, 2019

In pom.xml
spring-boot.version 2.0.6.RELEASE
spring-dynamodb-data-version 5.1.0

DynamoDBConfig.java

@Configuration
@EnableDynamoDBRepositories(dynamoDBMapperConfigRef = "dynamoDBMapperConfig",
		basePackages = "... my packages here ...")
public class DynamoConfig {

	@Value("${amazon.aws.accesskey}")
	private String amazonAWSAccessKey;

	@Value("${amazon.aws.secretkey}")
	private String amazonAWSSecretKey;

	@Value("${amazon.aws.dynamodb.tablename.prefix}")
	private String tableNamePrefix;

	@Bean
	public AmazonDynamoDB amazonDynamoDB() {

		return AmazonDynamoDBClientBuilder.standard()
				.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(amazonAWSAccessKey, amazonAWSSecretKey)))
				.withRegion(Regions.DEFAULT_REGION).build();
	}

	@Bean
	public DynamoDBMapperConfig dynamoDBMapperConfig(TableNameOverride tableNameOverrider) {
		// Create empty DynamoDBMapperConfig builder
		DynamoDBMapperConfig.Builder builder = DynamoDBMapperConfig.builder();
		// Inject the table name overrider bean
		builder.setTableNameOverride(tableNameOverrider);

		// Sadly this is a @deprecated method but new DynamoDBMapperConfig.Builder() is incomplete compared to DynamoDBMapperConfig.DEFAULT
		return new DynamoDBMapperConfig(DynamoDBMapperConfig.DEFAULT, builder.build());
	}

	@Bean
	public TableNameOverride tableNameOverrider() {
		return TableNameOverride.withTableNamePrefix( tableNamePrefix );
	}
}

When running:

2019-02-12 17:05:19,007 [main ] WARN letWebServerApplicationContext 87 - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'serviceImpl': Unsatisfied dependency expressed through field 'repository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'repository': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'dynamoDBMapperConfig' of bean class [org.socialsignin.spring.data.dynamodb.repository.support.DynamoDBRepositoryFactoryBean]: Bean property 'dynamoDBMapperConfig' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
"

@dinoo333
Copy link
Author

Duplicate of derjust/spring-data-dynamodb#233

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant