title: BeanDefinitionOverrideException caused by 2 @EnableJpaRepository
body: <p>I'm trying to implement custom functionality in my SpringBoot repository by following the instructions <a href="https://www.baeldung.com/spring-data-jpa-method-in-all-repositories" rel="nofollow noreferrer">here</a> for creating a new base repository class and adding it to the <code>@EnableJpaRepositories</code> annotation.
  However, when I do that, I get the following error:</p>
  <p><strong>Stacktrace</strong></p>
  <blockquote>
  <p><code>Caused by: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'myRepository' defined in com.my.service.repository.MyRepository defined in @EnableJpaRepositories declared on UpperLevelJpaConfig: Cannot register bean definition [Root bean: class [com.my.data.entity.base.BaseRepositoryFactoryBean]; scope=; abstract=false; lazyInit=true; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in com.my.service.repository.MyRepository defined in @EnableJpaRepositories declared on UpperLevelJpaConfig] for bean 'myRepository': There is already [Root bean: class [com.my.service.repository.BaseRepositoryFactoryBean2]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in com.my.service.repository.MyRepository defined in @EnableJpaRepositories declared on MyServiceApplication] bound.</code></p>
  </blockquote>
  <p>After looking <a href="https://www.baeldung.com/spring-boot-bean-definition-override-exception" rel="nofollow noreferrer">at this tutorial about the Exception type</a>, I think I understand that it's trying to create my repositories twice - once from my annotation, and once from the other annotation.</p>
  <p>Is there any way to get around this? I can't change the config file or how it is applied to my service, because it comes from higher up in the project structure.</p>
  <p>Thanks in advance!</p>
  <p>Edited to add some more code:</p>
  <p>My service class:</p>
  <pre><code>@SpringBootApplication
  @RefreshScope
  @EnableConfigurationProperties
  @EnableDiscoveryClient
  @EnableTransactionManagement
  @EnableJpaRepositories(repositoryFactoryBeanClass = BaseRepositoryFactoryBean2.class)
  @ComponentScan(
      basePackages = {
        &quot;com.my.service&quot;,
      })
  public class MyServiceApplication {
  }
  </code></pre>
  <p>The UpperLevelJpaConfig class:</p>
  <pre><code>@Configuration
  @EnableConfigurationProperties(value = {PoolDataSourceConfig.class, JpaProperties.class})
  @EnableTransactionManagement
  @EnableJpaRepositories(
      bootstrapMode = BootstrapMode.LAZY,
      basePackages = &quot;${\jpa.repositoryPackagePath:null}&quot;,
      repositoryFactoryBeanClass = BaseRepositoryFactoryBean.class)
  public class UpperLevelJpaConfig{
  }
  </code></pre>