spring-data-dynamodb
spring-data-dynamodb copied to clipboard
dynamodb does not work with mysql :spring-data-dynamodb does not work with jpa
Expected Behavior
Expecting to connect to both mysql and dynamodb. The connections work individually, but not together I also followed suggestions described here: https://github.com/derjust/spring-data-dynamodb/issues/127 But after doing the above, dynamodb throws a mapping error
Actual Behavior
The bean 'dynamoDB-DynamoDBMapperConfig', defined in null, could not be registered. A bean with that name has already been defined in null and overriding is disabled.
Steps to Reproduce the Problem
Use "spring-boot-starter-data-jpa" within dependecies Create some repos for MySQL entities Create a DynamoDBTable entity Create DynamoDBConfig class Create DynamoDB Crude Repository Start the app
Here is my code:
@Configuration @EnableJpaRepositories(includeFilters = { //or use basePackages or excludeFilters @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {UserRepository.class}) }) @EnableDynamoDBRepositories(includeFilters = { //or use basePackages or excludeFilters @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {KeysRepository.class}) }) public class DynamoDBConfig {
@Value("${amazon.dynamodb.endpoint}")
private String amazonDynamoDBEndpoint;
@Value("${amazon.aws.accesskey}")
private String amazonAWSAccessKey;
@Value("${amazon.aws.secretkey}")
private String amazonAWSSecretKey;
@Value("${amazon.aws.region}")
private String amazonAWSRegion;
@Bean
public AmazonDynamoDB amazonDynamoDB() {
AmazonDynamoDB amazonDynamoDB = AmazonDynamoDBClientBuilder.standard().withEndpointConfiguration(
new AwsClientBuilder.EndpointConfiguration(
amazonDynamoDBEndpoint, amazonAWSRegion))
.build();
return amazonDynamoDB;
}
}
@SpringBootApplication @EnableJpaRepositories(includeFilters = { //or use basePackages or excludeFilters @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {UserRepository.class}) }) @EnableDynamoDBRepositories(includeFilters = { //or use basePackages or excludeFilters @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {KeysRepository.class}) }) public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
@EnableScan public interface KeysRepository extends CrudRepository<Keys, String> { List<ApiKeys> findByKey(String key); }
@Data @DynamoDBTable(tableName = "keys") public class Keys implements Serializable { @DynamoDBHashKey private String key;
@DynamoDBAttribute
private String email;
public ApiKeys() {
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
@Repository public interface UserRepository extends JpaRepository<User, String> {
User findByUid(String uid);
}
Specifications
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-dynamodb</artifactId>
<version>1.11.470</version>
</dependency>
<dependency>
<groupId>com.github.derjust</groupId>
<artifactId>spring-data-dynamodb</artifactId>
<version>5.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.3</version>
</dependency>
</dependencies>
- Spring Data DynamoDB Version:
- Spring Data Version:
- AWS SDK Version:
- Java Version: 1.8
- Platform Details:
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.
Did you try to override internal beans ? By changing configuration ?
spring: main: allow-bean-definition-overriding: true
Fixed here
api group: 'io.github.boostchicken', name: 'spring-data-dynamodb', version: '5.2.1'
This bug is still happening with api group: 'io.github.boostchicken', name: 'spring-data-dynamodb', version: '5.2.1'