title: Spring Boot jdbc datasource autoconfiguration fails on standalone tomcat
body: <p>While trying to deploy and start a spring boot application on a standalone tomcat (7) instance, we ran into an issue were the autoconfigured spring datasource bean isn't found and the corresponding exception is thrown:</p>
  
  <pre><code>Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: 
  No qualifying bean of type [javax.sql.DataSource] found for dependency: 
  expected at least 1 bean which qualifies as autowire candidate for this dependency. 
  Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}    at
       org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1060)  at 
      org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:920)   at 
      org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:815)     at 
      org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480)   ... 84 more
  </code></pre>
  
  <p>The simple jdbc spring.datasource is properly configured in the application.properties and the application itself runs perfectly with an embedded tomcat instance as a standalone spring boot application.</p>
  
  <p>It seems as if the application.properties file cannot be read and/or processed properly, or the injection of some other beans (a service in a REST controller for example) is triggered before the datasource autoconfiguration has been done.</p>
  
  <p>Is any extra configuration required when not using an embedded tomcat?
  Or has anyone run into similar issues?</p>
  
  <p>The simple application and configuration:</p>
  
  <pre><code>@EnableAutoConfiguration
  @Configuration
  @ComponentScan("com.foo")
  public class Application extends SpringBootServletInitializer {
  
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);
      }
  
      @Override
      protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
          return application.sources(Application.class);
      }
  
  }
  </code></pre>
  
  <p>application.properties:</p>
  
  <pre><code>spring.datasource.url=jdbc:mysql://localhost:3306/mydatabase
  spring.datasource.username=username
  spring.datasource.password=password
  spring.datasource.driverClassName=com.mysql.jdbc.Driver
  </code></pre>
  
  <p>Datasource usage example:</p>
  
  <pre><code>@Repository
  public class MyRepositoryImpl implements MyRepository {
  
      @Autowired
      private DataSource dataSource;
  
  ...
  }
  </code></pre>
  
  <p>Pom parent &amp; dependencies:</p>
  
  <pre><code>&lt;parent&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
      &lt;version&gt;0.5.0.M6&lt;/version&gt;
  &lt;/parent&gt;
  
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;mysql&lt;/groupId&gt;
          &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
          &lt;version&gt;5.1.27&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-jdbc&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
          &lt;version&gt;4.0.0.RC1&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>
  
  <p>Auto configuration report of failed start:</p>
  
  <pre><code>=========================
  AUTO-CONFIGURATION REPORT
  =========================
  
  
  Positive matches:
  -----------------
  
     MessageSourceAutoConfiguration
        - @ConditionalOnMissingBean (types: org.springframework.context.MessageSource; SearchStrategy: all) found no beans (OnBeanCondition)
  
     PropertyPlaceholderAutoConfiguration#propertySourcesPlaceholderConfigurer
        - @ConditionalOnMissingBean (types: org.springframework.context.support.PropertySourcesPlaceholderConfigurer; SearchStrategy: current) found no beans (OnBeanCondition)
  
     DataSourceAutoConfiguration
        - @ConditionalOnClass classes found: org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType (OnClassCondition)
        - @ConditionalOnClass classes found: org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType (OnClassCondition)
  
     DataSourceAutoConfiguration.JdbcTemplateConfiguration
        - existing auto database detected (DataSourceAutoConfiguration.DatabaseCondition)
        - existing auto database detected (DataSourceAutoConfiguration.DatabaseCondition)
  
     DataSourceAutoConfiguration.JdbcTemplateConfiguration#jdbcTemplate
        - @ConditionalOnMissingBean (types: org.springframework.jdbc.core.JdbcOperations; SearchStrategy: all) found no beans (OnBeanCondition)
  
     DataSourceAutoConfiguration.JdbcTemplateConfiguration#namedParameterJdbcTemplate
        - @ConditionalOnMissingBean (types: org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations; SearchStrategy: all) found no beans (OnBeanCondition)
  
     DataSourceAutoConfiguration.TomcatConfiguration
        - found database driver com.mysql.jdbc.Driver (DataSourceAutoConfiguration.TomcatDatabaseCondition)
        - found database driver com.mysql.jdbc.Driver (DataSourceAutoConfiguration.TomcatDatabaseCondition)
        - @ConditionalOnMissingBean (types: javax.sql.DataSource; SearchStrategy: all) found no beans (OnBeanCondition)
  
     DataSourceTransactionManagerAutoConfiguration
        - @ConditionalOnClass classes found: org.springframework.jdbc.core.JdbcTemplate,org.springframework.transaction.PlatformTransactionManager (OnClassCondition)
        - @ConditionalOnClass classes found: org.springframework.jdbc.core.JdbcTemplate,org.springframework.transaction.PlatformTransactionManager (OnClassCondition)
  
     DataSourceTransactionManagerAutoConfiguration#transactionManager
        - @ConditionalOnBean (types: javax.sql.DataSource; SearchStrategy: all) found the following [dataSource] @ConditionalOnMissingBean (names: transactionManager; SearchStrategy: all) found no beans (OnBeanCondition)
        - @ConditionalOnBean (types: javax.sql.DataSource; SearchStrategy: all) found the following [dataSource] @ConditionalOnMissingBean (names: transactionManager; SearchStrategy: all) found no beans (OnBeanCondition)
  
     DispatcherServletAutoConfiguration
        - found web application StandardServletEnvironment (OnWebApplicationCondition)
        - @ConditionalOnClass classes found: org.springframework.web.servlet.DispatcherServlet (OnClassCondition)
        - found web application StandardServletEnvironment (OnWebApplicationCondition)
        - @ConditionalOnClass classes found: org.springframework.web.servlet.DispatcherServlet (OnClassCondition)
        - @ConditionalOnBean (types: org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; SearchStrategy: all) found the following [tomcatEmbeddedServletContainerFactory] (OnBeanCondition)
  
     DispatcherServletAutoConfiguration#dispatcherServlet
        - no DispatcherServlet found (DispatcherServletAutoConfiguration.DefaultDispatcherServletCondition)
  
     EmbeddedServletContainerAutoConfiguration
        - found web application StandardServletEnvironment (OnWebApplicationCondition)
        - found web application StandardServletEnvironment (OnWebApplicationCondition)
  
     EmbeddedServletContainerAutoConfiguration.EmbeddedTomcat
        - @ConditionalOnClass classes found: javax.servlet.Servlet,org.apache.catalina.startup.Tomcat (OnClassCondition)
        - @ConditionalOnClass classes found: javax.servlet.Servlet,org.apache.catalina.startup.Tomcat (OnClassCondition)
        - @ConditionalOnMissingBean (types: org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; SearchStrategy: current) found no beans (OnBeanCondition)
  
     ServerPropertiesAutoConfiguration#serverProperties
        - @ConditionalOnMissingBean (types: org.springframework.boot.context.embedded.properties.ServerProperties; SearchStrategy: all) found no beans (OnBeanCondition)
  
     WebMvcAutoConfiguration
        - found web application StandardServletEnvironment (OnWebApplicationCondition)
        - @ConditionalOnClass classes found: javax.servlet.Servlet,org.springframework.web.servlet.DispatcherServlet,org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter (OnClassCondition)
        - found web application StandardServletEnvironment (OnWebApplicationCondition)
        - @ConditionalOnClass classes found: javax.servlet.Servlet,org.springframework.web.servlet.DispatcherServlet,org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter (OnClassCondition)
        - @ConditionalOnMissingBean (types: org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; SearchStrategy: all) found no beans (OnBeanCondition)
  
     WebMvcAutoConfiguration#hiddenHttpMethodFilter
        - @ConditionalOnMissingBean (types: org.springframework.web.filter.HiddenHttpMethodFilter; SearchStrategy: all) found no beans (OnBeanCondition)
  
     WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#defaultViewResolver
        - @ConditionalOnMissingBean (types: org.springframework.web.servlet.view.InternalResourceViewResolver; SearchStrategy: all) found no beans (OnBeanCondition)
  
  
  Negative matches:
  -----------------
  
     RabbitAutoConfiguration
        - required @ConditionalOnClass classes not found: org.springframework.amqp.rabbit.core.RabbitTemplate,com.rabbitmq.client.Channel (OnClassCondition)
  
     AopAutoConfiguration
        - required @ConditionalOnClass classes not found: org.aspectj.lang.annotation.Aspect,org.aspectj.lang.reflect.Advice (OnClassCondition)
  
     BatchAutoConfiguration
        - required @ConditionalOnClass classes not found: org.springframework.batch.core.launch.JobLauncher (OnClassCondition)
  
     JpaRepositoriesAutoConfiguration
        - required @ConditionalOnClass classes not found: org.springframework.data.jpa.repository.JpaRepository (OnClassCondition)
  
     MongoRepositoriesAutoConfiguration
        - required @ConditionalOnClass classes not found: com.mongodb.Mongo,org.springframework.data.mongodb.repository.MongoRepository (OnClassCondition)
  
     DataSourceAutoConfiguration.DbcpConfiguration
        - tomcat DataSource (DataSourceAutoConfiguration.BasicDatabaseCondition)
  
     DataSourceAutoConfiguration.EmbeddedConfiguration
        - existing non-embedded database detected (DataSourceAutoConfiguration.EmbeddedDatabaseCondition)
  
     JmsTemplateAutoConfiguration
        - required @ConditionalOnClass classes not found: org.springframework.jms.core.JmsTemplate,javax.jms.ConnectionFactory (OnClassCondition)
  
     DeviceResolverAutoConfiguration
        - required @ConditionalOnClass classes not found: org.springframework.mobile.device.DeviceResolverHandlerInterceptor,org.springframework.mobile.device.DeviceHandlerMethodArgumentResolver (OnClassCondition)
  
     HibernateJpaAutoConfiguration
        - required @ConditionalOnClass classes not found: javax.persistence.EntityManager,org.hibernate.ejb.HibernateEntityManager (OnClassCondition)
  
     ReactorAutoConfiguration
        - required @ConditionalOnClass classes not found: reactor.spring.context.config.EnableReactor (OnClassCondition)
  
     ThymeleafAutoConfiguration
        - required @ConditionalOnClass classes not found: org.thymeleaf.spring3.SpringTemplateEngine (OnClassCondition)
  
     EmbeddedServletContainerAutoConfiguration.EmbeddedJetty
        - required @ConditionalOnClass classes not found: org.eclipse.jetty.server.Server,org.eclipse.jetty.util.Loader (OnClassCondition)
  
     MultipartAutoConfiguration
        - @ConditionalOnClass classes found: javax.servlet.Servlet,org.springframework.web.multipart.support.StandardServletMultipartResolver (OnClassCondition)
        - @ConditionalOnClass classes found: javax.servlet.Servlet,org.springframework.web.multipart.support.StandardServletMultipartResolver (OnClassCondition)
        - @ConditionalOnBean (types: javax.servlet.MultipartConfigElement; SearchStrategy: all) found no beans (OnBeanCondition)
  
     WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#beanNameViewResolver
        - @ConditionalOnBean (types: org.springframework.web.servlet.View; SearchStrategy: all) found no beans (OnBeanCondition)
  
     WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#viewResolver
        - @ConditionalOnBean (types: org.springframework.web.servlet.View; SearchStrategy: all) found no beans (OnBeanCondition)
  
     WebSocketAutoConfiguration
        - required @ConditionalOnClass classes not found: org.springframework.web.socket.WebSocketHandler (OnClassCondition)
  </code></pre>
  
  <p>Thanks</p>