主题:beetlsql无法拿到datasource

weilai 2018年02月07日 50

两个项目都使用druid-spring-boot-starter 1.1.6beetl-framework-starter1.1.32

其中一个项目dao层 Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)},

应该是beetlsql没找到datasource,注入失败. 自己写的配置类返回datasource就可以成功启动,

启动失败的项目springboot debug 部分日志如下:

=========================
AUTO-CONFIGURATION REPORT
=========================


Positive matches:
-----------------

   BeetlTemplateConfig matched:
      - @ConditionalOnProperty (beetl.enabled=true) matched (OnPropertyCondition)

   BeetlTemplateConfig#getBeetlGroupUtilConfiguration matched:
      - @ConditionalOnMissingBean (names: beetlConfig; SearchStrategy: all) did not find any beans (OnBeanCondition)

   BeetlTemplateConfig#getBeetlSpringViewResolver matched:
      - @ConditionalOnMissingBean (names: beetlViewResolver; SearchStrategy: all) did not find any beans (OnBeanCondition)

   BeetlTemplateConfig#getGroupTemplate matched:
      - @ConditionalOnMissingBean (types: org.beetl.core.GroupTemplate; SearchStrategy: all) did not find any beans (OnBeanCondition)

   DataSourceAutoConfiguration matched:
      - @ConditionalOnClass found required classes 'javax.sql.DataSource', 'org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType'; @ConditionalOnMissingClass did not find unwanted class (OnClassCondition)

   DataSourceAutoConfiguration#dataSourceInitializer matched:
      - @ConditionalOnMissingBean (types: org.springframework.boot.autoconfigure.jdbc.DataSourceInitializer; SearchStrategy: all) did not find any beans (OnBeanCondition)

   DataSourceTransactionManagerAutoConfiguration matched:
      - @ConditionalOnClass found required classes 'org.springframework.jdbc.core.JdbcTemplate', 'org.springframework.transaction.PlatformTransactionManager'; @ConditionalOnMissingClass did not find unwanted class (OnClassCondition)

   DataSourceTransactionManagerAutoConfiguration.DataSourceTransactionManagerConfiguration matched:
      - @ConditionalOnSingleCandidate (types: javax.sql.DataSource; SearchStrategy: all) found a primary bean from beans 'dataSource' (OnBeanCondition)

   DataSourceTransactionManagerAutoConfiguration.DataSourceTransactionManagerConfiguration#transactionManager matched:
      - @ConditionalOnMissingBean (types: org.springframework.transaction.PlatformTransactionManager; SearchStrategy: all) did not find any beans (OnBeanCondition)

   DruidDataSourceAutoConfigure matched:
      - @ConditionalOnClass found required class 'com.alibaba.druid.pool.DruidDataSource'; @ConditionalOnMissingClass did not find unwanted class (OnClassCondition)

   DruidDataSourceAutoConfigure#dataSource matched:
      - @ConditionalOnMissingBean (types: javax.sql.DataSource; SearchStrategy: all) did not find any beans (OnBeanCondition)

   DruidFilterConfiguration#statFilter matched:
      - @ConditionalOnProperty (spring.datasource.druid.filter.stat.enabled) matched (OnPropertyCondition)
      - @ConditionalOnMissingBean (types: com.alibaba.druid.filter.stat.StatFilter; SearchStrategy: all) did not find any beans (OnBeanCondition)


Negative matches:
-----------------

   ActiveMQAutoConfiguration:
      Did not match:
         - @ConditionalOnClass did not find required classes 'javax.jms.ConnectionFactory', 'org.apache.activemq.ActiveMQConnectionFactory' (OnClassCondition)

   AopAutoConfiguration:
      Did not match:
         - @ConditionalOnClass did not find required classes 'org.aspectj.lang.annotation.Aspect', 'org.aspectj.lang.reflect.Advice' (OnClassCondition)

   ArtemisAutoConfiguration:
      Did not match:
         - @ConditionalOnClass did not find required classes 'javax.jms.ConnectionFactory', 'org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory' (OnClassCondition)

   BatchAutoConfiguration:
      Did not match:
         - @ConditionalOnClass did not find required class 'org.springframework.batch.core.launch.JobLauncher' (OnClassCondition)

   BeetlSqlConfig:
      Did not match:
         - @ConditionalOnBean (types: javax.sql.DataSource; SearchStrategy: all) did not find any beans (OnBeanCondition)
      Matched:
         - @ConditionalOnProperty (beetlsql.enabled=true) matched (OnPropertyCondition)


==========================

另一个启动成功项目部分debug日志如下:


=========================
AUTO-CONFIGURATION REPORT
=========================


Positive matches:
-----------------

   BeetlSqlConfig matched:
      - @ConditionalOnProperty (beetlsql.enabled=true) matched (OnPropertyCondition)
      - @ConditionalOnBean (types: javax.sql.DataSource; SearchStrategy: all) found bean 'dataSource' (OnBeanCondition)

   BeetlSqlConfig#beetlSqlDataSource matched:
      - @ConditionalOnMissingBean (types: org.beetl.sql.ext.spring4.BeetlSqlDataSource; SearchStrategy: all) did not find any beans (OnBeanCondition)

   BeetlSqlConfig#getSqlManagerFactoryBean matched:
      - @ConditionalOnMissingBean (types: org.beetl.sql.ext.spring4.SqlManagerFactoryBean; SearchStrategy: all) did not find any beans (OnBeanCondition)

   BeetlTemplateConfig matched:
      - @ConditionalOnProperty (beetl.enabled=true) matched (OnPropertyCondition)

   BeetlTemplateConfig#getBeetlGroupUtilConfiguration matched:
      - @ConditionalOnMissingBean (names: beetlConfig; SearchStrategy: all) did not find any beans (OnBeanCondition)

   BeetlTemplateConfig#getBeetlSpringViewResolver matched:
      - @ConditionalOnMissingBean (names: beetlViewResolver; SearchStrategy: all) did not find any beans (OnBeanCondition)

   BeetlTemplateConfig#getGroupTemplate matched:
      - @ConditionalOnMissingBean (types: org.beetl.core.GroupTemplate; SearchStrategy: all) did not find any beans (OnBeanCondition)

   DataSourceAutoConfiguration matched:
      - @ConditionalOnClass found required classes 'javax.sql.DataSource', 'org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType'; @ConditionalOnMissingClass did not find unwanted class (OnClassCondition)

   DataSourceAutoConfiguration#dataSourceInitializer matched:
      - @ConditionalOnMissingBean (types: org.springframework.boot.autoconfigure.jdbc.DataSourceInitializer; SearchStrategy: all) did not find any beans (OnBeanCondition)

   DataSourceConfiguration.Tomcat matched:
      - @ConditionalOnClass found required class 'org.apache.tomcat.jdbc.pool.DataSource'; @ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
      - @ConditionalOnProperty (spring.datasource.type=org.apache.tomcat.jdbc.pool.DataSource) matched (OnPropertyCondition)

   DataSourcePoolMetadataProvidersConfiguration.TomcatDataSourcePoolMetadataProviderConfiguration matched:
      - @ConditionalOnClass found required class 'org.apache.tomcat.jdbc.pool.DataSource'; @ConditionalOnMissingClass did not find unwanted class (OnClassCondition)

   DataSourceTransactionManagerAutoConfiguration matched:
      - @ConditionalOnClass found required classes 'org.springframework.jdbc.core.JdbcTemplate', 'org.springframework.transaction.PlatformTransactionManager'; @ConditionalOnMissingClass did not find unwanted class (OnClassCondition)

   DataSourceTransactionManagerAutoConfiguration.DataSourceTransactionManagerConfiguration matched:
      - @ConditionalOnSingleCandidate (types: javax.sql.DataSource; SearchStrategy: all) found a primary bean from beans 'dataSource' (OnBeanCondition)

   DataSourceTransactionManagerAutoConfiguration.DataSourceTransactionManagerConfiguration#transactionManager matched:
      - @ConditionalOnMissingBean (types: org.springframework.transaction.PlatformTransactionManager; SearchStrategy: all) did not find any beans (OnBeanCondition)

   DispatcherServletAutoConfiguration matched:
      - @ConditionalOnClass found required class 'org.springframework.web.servlet.DispatcherServlet'; @ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
      - @ConditionalOnWebApplication (required) found StandardServletEnvironment (OnWebApplicationCondition)

   DispatcherServletAutoConfiguration.DispatcherServletConfiguration matched:
      - @ConditionalOnClass found required class 'javax.servlet.ServletRegistration'; @ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
      - Default DispatcherServlet did not find dispatcher servlet beans (DispatcherServletAutoConfiguration.DefaultDispatcherServletCondition)

   DispatcherServletAutoConfiguration.DispatcherServletRegistrationConfiguration matched:
      - @ConditionalOnClass found required class 'javax.servlet.ServletRegistration'; @ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
      - DispatcherServlet Registration did not find servlet registration bean (DispatcherServletAutoConfiguration.DispatcherServletRegistrationCondition)

   DispatcherServletAutoConfiguration.DispatcherServletRegistrationConfiguration#dispatcherServletRegistration matched:
      - @ConditionalOnBean (names: dispatcherServlet; types: org.springframework.web.servlet.DispatcherServlet; SearchStrategy: all) found beans 'dispatcherServlet', 'dispatcherServlet' (OnBeanCondition)

   DruidDataSourceAutoConfigure matched:
      - @ConditionalOnClass found required class 'com.alibaba.druid.pool.DruidDataSource'; @ConditionalOnMissingClass did not find unwanted class (OnClassCondition)

   DruidDataSourceAutoConfigure#dataSource matched:
      - @ConditionalOnMissingBean (types: javax.sql.DataSource; SearchStrategy: all) did not find any beans (OnBeanCondition)

   DruidFilterConfiguration#statFilter matched:
      - @ConditionalOnProperty (spring.datasource.druid.filter.stat.enabled) matched (OnPropertyCondition)
      - @ConditionalOnMissingBean (types: com.alibaba.druid.filter.stat.StatFilter; SearchStrategy: all) did not find any beans (OnBeanCondition)

   DruidStatViewServletConfiguration matched:
      - @ConditionalOnWebApplication (required) found StandardServletEnvironment (OnWebApplicationCondition)
      - @ConditionalOnProperty (spring.datasource.druid.stat-view-servlet.enabled=true) matched (OnPropertyCondition)

   DruidWebStatFilterConfiguration matched:
      - @ConditionalOnWebApplication (required) found StandardServletEnvironment (OnWebApplicationCondition)
      - @ConditionalOnProperty (spring.datasource.druid.web-stat-filter.enabled=true) matched (OnPropertyCondition)

成功启动项目Negative matches里没有beetlsql 就不贴了.


大赋可以帮忙分析一下是什么问题吗,两个项目配置是一样的.万分感谢!

提前祝 新年大吉!

闲大赋 2018年02月07日

我的例子都是自己写的DataSource,我自己还从未试过配置文件自动配置,想来区别不大。你的错误具体信息是什么

  • weilai:大赋,错误在楼下. 自己写datasource是可以的,不过自动配置一个项目可以另一个不行也让我挺困惑的,不知道是不是哪里配置的不对(2018年02月08日)
weilai 2018年02月08日

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'xxx.xxx.xxxDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

dao接口是继承basemapper的.

作者:闲大赋
官网:
qq群:219324263
微信捐助开源 支付宝捐助开源