FlywayAutoConfiguration不“看到”数据源

时间:2017-11-05 21:43:52

标签: spring spring-boot flyway

在类路径上使用带有web starter和flywaydb的spring boot 2.0.0.M5。 自动配置调试输出一方面显示了按预期配置的数据源:

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

DataSourceAutoConfiguration.PooledDataSourceConfiguration matched:
  - AnyNestedCondition 1 matched 1 did not; NestedCondition on DataSourceAutoConfiguration.PooledDataSourceCondition.PooledDataSourceAvailable PooledDataSource found supported DataSource; NestedCondition on DataSourceAutoConfiguration.PooledDataSourceCondition.ExplicitType @ConditionalOnProperty (spring.datasource.type) did not find property 'type' (DataSourceAutoConfiguration.PooledDataSourceCondition)
  - @ConditionalOnMissingBean (types: javax.sql.DataSource,javax.sql.XADataSource; SearchStrategy: all) did not find any beans (OnBeanCondition)

DataSourceConfiguration.Hikari matched:
  - @ConditionalOnClass found required class 'com.zaxxer.hikari.HikariDataSource'; @ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
  - @ConditionalOnProperty (spring.datasource.type=com.zaxxer.hikari.HikariDataSource) matched (OnPropertyCondition)

另一方面,由于“缺少(?!)”数据源,自动配置无法配置FlywayAutoConfiguration

FlywayAutoConfiguration:
  Did not match:
     - @ConditionalOnBean (types: javax.sql.DataSource; SearchStrategy: all) did not find any beans of type javax.sql.DataSource (OnBeanCondition)
  Matched:
     - @ConditionalOnClass found required class 'org.flywaydb.core.Flyway'; @ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
     - @ConditionalOnProperty (spring.flyway.enabled) matched (OnPropertyCondition)

任何有关如何修复(或至少进一步调试)的建议都将非常感谢!

1 个答案:

答案 0 :(得分:0)

与Spring Boot 2.0.2相同的问题。

我不是真的为什么看不到它,但是当手动实例化dataSource修复它时:

@Bean
public DataSource dataSource(//
        @Value("${spring.datasource.url}") String url, //
        @Value("${spring.datasource.username}") String username, //
        @Value("${spring.datasource.password}") String password, //
        @Value("${spring.datasource.driver-class}") String driver, //
        @Value("${spring.datasource.hikari.connection-timeout:30}") Long timeout, //
        @Value("${spring.datasource.hikari.maximum-pool-size:20}") Integer maxPoolSize  ) {

    HikariConfig config = new HikariConfig();
    config.setJdbcUrl(url);
    config.setUsername(username);
    config.setPassword(password);
    config.setDriverClassName(driver);
    config.setConnectionTimeout(timeout);
    config.setMaximumPoolSize(maxPoolSize);

    return new HikariDataSource(config);
}