title: Spring Boot application-The bean could not be registered
body: <p>I have just created a new Spring-boot-starter project and I am trying to use <code>MongoRepository</code> (Mentioning because I feel that this could be related to my problem) and I only have 4 classes that I am trying to run, like:</p>
  
  <p><strong>User.java</strong></p>
  
  <pre><code>@Entity
  public class User {
  
      @Column(name = "id")
      @Id
      private Long id;
  
      @Column(name = "name")
      private String name;
  
      @Column(name = "email")
      private String email;
  
      @Column(name = "password")
      private String password;
  }
  </code></pre>
  
  <p><strong>UserController.java</strong></p>
  
  <pre><code>@RestController
  public class UserController {
  
      @Autowired
      private UserRepository userRepository;
  
      @PostMapping("/AddUser")
      private ResponseEntity&lt;?&gt; getDistance(@RequestBody User user) throws Exception {
          userRepository.save(user);
          return ResponseEntity.ok(user);
      }
  }
  </code></pre>
  
  <p><strong>UserRepository.java</strong></p>
  
  <pre><code>@Repository
  public interface UserRepository extends MongoRepository&lt;User, Long&gt; {
  }
  </code></pre>
  
  <p><strong>Main Class</strong></p>
  
  <pre><code>@SpringBootApplication
  public class DemoApplication {
  
      public static void main(String[] args) {
          SpringApplication.run(DemoApplication.class, args);
      }
  
  }
  </code></pre>
  
  <p><strong>build.gradle</strong></p>
  
  <pre><code>plugins {
      id 'org.springframework.boot' version '2.2.5.RELEASE'
      id 'io.spring.dependency-management' version '1.0.9.RELEASE'
      id 'java'
  }
  
  group = 'com.javademos'
  version = '0.0.1-SNAPSHOT'
  sourceCompatibility = '1.8'
  
  repositories {
      mavenCentral()
  }
  
  dependencies {
      implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
      implementation 'org.springframework.boot:spring-boot-starter-web'
      compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-mongodb', version: '2.2.5.RELEASE'
      implementation 'com.google.maps:google-maps-services:0.1.7'
      testImplementation('org.springframework.boot:spring-boot-starter-test') {
          exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
      }
  }
  
  test {
      useJUnitPlatform()
  }
  </code></pre>
  
  <p><strong>Project Structure:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/vSMPJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vSMPJ.png" alt="enter image description here"></a></p>
  
  <p>But everytime I run the code I get an exception saying:</p>
  
  <pre><code>***************************
  APPLICATION FAILED TO START
  ***************************
  
  Description:
  
  The bean 'userRepository' could not be registered. A bean with that name has already been defined and overriding is disabled.
  
  Action:
  
  Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
  
  
  Process finished with exit code 1
  </code></pre>
  
  <p>I have double-checked and I am not using any annotation twice, Especially @Repository.</p>
  
  <p>I have seen <a href="https://stackoverflow.com/questions/51367566/trouble-when-changing-spring-boot-version-from-2-0-3-release-to-2-1-0-build-snap">this question</a> and it is still not working.</p>
  
  <p>I just want to know why exactly is it saying</p>
  
  <pre><code>The bean 'userRepository' could not be registered. A bean with that name has already been defined and overriding is disabled.
  </code></pre>
  
  <p>While I have only One Repository in my project</p>