Spring Boot Test不会加载应用程序上下文

时间:2019-01-23 10:29:17

标签: spring spring-boot

我在src / test / resources路径中创建了application-integrationtest.yaml,因此针对已创建的docker testcontainer运行测试。问题是我的application-integrationtest.yaml没有被加载。

我正在运行SpringBoot 2.x应用程序

这是我的数据源类

@Configuration
public class IndexModificationDatabaseConfiguration {

  @Bean
  public JOOQToSpringExceptionTransformer 
  jooqToSpringExceptionTransformer() {
    return new JOOQToSpringExceptionTransformer();
  }

  @Bean
  public DataSourceConnectionProvider connectionProvider(final DataSource 
  dataSource) {
    return new DataSourceConnectionProvider(new 
    TransactionAwareDataSourceProxy(dataSource));
  }

  @Bean(name = "indexModification")
  @ConfigurationProperties("index-modified.datasource")
  public DataSourceProperties dataSourceProperties() {
    return new DataSourceProperties();
  }

  @Bean
  public DataSource 
  indexModificationDataSource(@Qualifier("indexModification") final 
  DataSourceProperties properties) {
    return properties.initializeDataSourceBuilder().build();
  }

  @Bean
  public DSLContext 
  createIndexModifiedDslContext(@Qualifier("indexModificationDataSource") 
  final DataSource dataSource) {
    final DefaultConfiguration configuration = new DefaultConfiguration();
    configuration.set(connectionProvider(dataSource));
    configuration.set(new 
    DefaultExecuteListenerProvider(jooqToSpringExceptionTransformer()));
    configuration.set(SQLDialect.POSTGRES);
    return new DefaultDSLContext(configuration);
  }
}

这是我的测试

@RunWith(SpringRunner.class)
@SpringBootTest(classes = {IndexModificationDatabaseConfiguration.class})
@ActiveProfiles("integrationtest")
public class ContainerOrchestrator {

  @Test
  public void testContainer() {
  assertTrue(true);
  }
}

例外是

由以下原因引起:org.springframework.beans.BeanInstantiationException:无法实例化[javax.sql.DataSource]:工厂方法'indexModificationDataSource'引发了异常;嵌套异常为  org.springframework.boot.autoconfigure.jdbc.DataSourceProperties $ DataSourceBeanCreationException:无法确定合适的驱动程序类     在org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)     在org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:582)     ...更多55 原因:org.springframework.boot.autoconfigure.jdbc.DataSourceProperties $ DataSourceBeanCreationException:无法确定合适的驱动程序类

当我调试时,我看到我的数据源在驱动程序,网址,密码等上具有空值。

1 个答案:

答案 0 :(得分:0)

我认为您需要在配置类中添加@Profile注释