title: DataSource bean overriding in spring boot 2.1
body: <p>I have upgraded to spring boot 2.1 release and I have got strange exception when starting up the application.</p>
  
  <blockquote>
    <p>The bean 'dataSource', defined in BeanDefinition defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class] and overriding is disabled.</p>
  </blockquote>
  
  <p>The full error message is:</p>
  
  <blockquote>
    <p>[o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'dataSource' defined in BeanDefinition defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Cannot register bean definition [Root bean: class [org.springframework.aop.scope.ScopedProxyFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in BeanDefinition defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]] for bean 'dataSource': There is already [Root bean: class [null]; scope=refresh; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=false; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari; factoryMethodName=dataSource; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]] bound.</p>
  </blockquote>
  
  <p>Beans must not be overridden according to our policy and it's disabled with:</p>
  
  <pre><code>spring.main.allow-bean-definition-overriding=false
  </code></pre>
  
  <p>I don't have any data source configuration in my application code. The only option that triggers this error is <code>@EnableAutoConfiguration</code> and in my application properties I have set the data source type to:</p>
  
  <pre><code>spring.datasource.type=com.zaxxer.hikari.HikariDataSource
  </code></pre>
  
  <p>The boot application is initialized with</p>
  
  <pre><code>@SpringBootApplication
  @EnableAutoConfiguration
  public class MyApplication extends SpringBootServletInitializer {
  
      public static void main(String[] args) {
          new MyApplication()
              .configure(new SpringApplicationBuilder(MyApplication.class))
              .run(args);
      }
  }
  </code></pre>
  
  <p>There is also configuration class that imports various other configurations:</p>
  
  <pre><code>@Configuration
  @ImportResource(locations = {
      "classpath*:conf/spring/*.xml",
      "classpath*:conf/spring/core/*.xml",
      "classpath*:conf/spring/plugin/**/*.xml"
  })
  @EnableAsync
  @EnableRetry
  @EnableCaching
  @EnableBatchProcessing
  @EnableCircuitBreaker
  public class AppConfig {
      ...
  }
  </code></pre>
  
  <p>Does anyone knows what could cause that issue and where to search?</p>
  
  <p>It didn't happened prior to Spring Boot 2.1 (i.e. 2.0.5).</p>