title: SpringBoot - BeanDefinitionOverrideException: Invalid bean definition
body: <p>I am trying to setup DynamoDB locally with Spring Boot. Initially I got the setup working and was able to write/save to DynamoDB via a repository. From that point I added more classes to build my application. Now when I try to start my application, I get the following exception:</p>
  
  <blockquote>
    <p><code>org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'agentRepository' defined in null: Cannot register bean definition [Root bean: class [org.socialsignin.spring.data.dynamodb.repository.support.DynamoDBRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] for bean 'agentRepository': There is already [Root bean: class [org.socialsignin.spring.data.dynamodb.repository.support.DynamoDBRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] bound.</code></p>
  </blockquote>
  
  <p>I have searched SO and internet extensively but there were no any useful solution to this. The error message is misleading as well.</p>
  
  <p>My project is of the following hierarchy</p>
  
  <pre><code>ai.test.as
    - as
        - agent
            - business
            - intent
            - exception
            - Agent.java
            - AgentDTO.java
            - AgentRespository.java
            - AgentController.java
            - AgentService.java
            - AgentServiceImpl.java
    - config
       - DynamoDBConfig.java
  </code></pre>
  
  <p>DynamoDBConfig.java</p>
  
  <pre><code>package ai.test.as.config;
  
  import ai.test.as.agent.AgentRepository;
  import ai.test.as.agent.intent.template.TemplateRepository;
  import com.amazonaws.auth.AWSCredentials;
  import com.amazonaws.auth.BasicAWSCredentials;
  import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
  import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;
  import org.socialsignin.spring.data.dynamodb.repository.config.EnableDynamoDBRepositories;
  import org.springframework.beans.factory.annotation.Value;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  
  @Configuration
  @EnableDynamoDBRepositories(basePackageClasses = {AgentRepository.class})
  public class DynamoDBConfig
  {
      @Value("${aws.dynamodb.endpoint}")
      private String dynamoDBEndpoint;
  
      @Value("${aws.auth.accesskey}")
      private String awsAccessKey;
  
      @Value("${aws.auth.secretkey}")
      private String awsSecretKey;
  
      @Bean
      public AmazonDynamoDB amazonDynamoDB()
      {
          AmazonDynamoDB dynamoDB = new AmazonDynamoDBClient(getAwsCredentials());
          dynamoDB.setEndpoint(dynamoDBEndpoint);
  
          return dynamoDB;
      }
  
      @Bean
      public AWSCredentials getAwsCredentials()
      {
          return new BasicAWSCredentials(awsAccessKey, awsSecretKey);
      }
  }
  </code></pre>
  
  <p>AgentRepository.java</p>
  
  <pre><code>package ai.test.as.agent;
  
  import ai.test.as.agent.Agent;
  import org.socialsignin.spring.data.dynamodb.repository.EnableScan;
  import org.springframework.data.repository.CrudRepository;
  
  @EnableScan
  public interface AgentRepository extends CrudRepository&lt;Agent, String&gt;
  {
  }
  </code></pre>
  
  <p>AgentController.java (Where AgentRepository is used)</p>
  
  <pre><code>@RestController
  @RequestMapping(value = "/v1/agents")
  public class AgentController
  {
      @Autowired
      private AgentRepository agentRepository;
  
      @RequestMapping(value = "/test", method = RequestMethod.POST)
      public void test()
      {
          Agent agent = new Agent();
          agent.setAgentNumber("123456");
          agent.setId(1);
  
          agentRepository.save(agent);
      }
  }
  </code></pre>
  
  <p>Spring suggests the following:
  <code>&gt; The bean 'agentRepository', defined in null, could not be registered. A bean with that name has already been defined in null and overriding is disabled</code>.</p>
  
  <p>What does <code>null</code> mean here? Is it because something wrong in my application config? Also how is it possible that it is already registered?</p>
  
  <p>Please give me some pointers because I so confused about my next steps.</p>