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

dynamodb does not work with mysql :spring-data-dynamodb does not work with jpa #260

Open suranjanabasu opened 5 years ago

suranjanabasu commented 5 years ago

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

org.springframework.boot spring-boot-starter-security org.springframework.boot spring-boot-starter-web com.amazonaws aws-java-sdk-dynamodb 1.11.470 com.github.derjust spring-data-dynamodb 5.1.0 org.springframework.boot spring-boot-starter-test test org.springframework.security spring-security-test test org.projectlombok lombok 1.18.8 provided org.springframework.boot spring-boot-starter-data-jpa org.apache.httpcomponents httpclient mysql mysql-connector-java commons-beanutils commons-beanutils 1.9.3

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.

tanguc commented 5 years ago

Did you try to override internal beans ? By changing configuration ?

spring: main: allow-bean-definition-overriding: true

boostchicken commented 4 years ago

Fixed here

api group: 'io.github.boostchicken', name: 'spring-data-dynamodb', version: '5.2.1'

marcelweigle commented 3 years ago

This bug is still happening with api group: 'io.github.boostchicken', name: 'spring-data-dynamodb', version: '5.2.1'