代码之家  ›  专栏  ›  技术社区  ›  abierto

与Spring Boot的集成测试

  •  2
  • abierto  · 技术社区  · 8 年前

    我拥有的: 我正在开发一个微服务,将Spring Boot与Web和SpringMyBatis结合使用。

    我的问题: 既然我想创建将在两个数据库上运行的集成测试,并且我必须使用不同的JDBC驱动程序(我的测试将直接在数据库上检查插入/修改的内容),那么最好的方法是什么?

    2 回复  |  直到 8 年前
        1
  •  2
  •   StanislavL    8 年前

    正如我提到的,使用spring profile很好。定义2个带注释的数据源 @Profile("dev") @Profile("qa")

    看见 the example the example 获取更多信息

        2
  •  1
  •   M. Deinum    8 年前

    application-<profile>.properties (或 .yml 弹簧靴将加载适当的。

    application-qa.properties 您可以指定以下内容

    spring.datasource.url=jdbc:mysql:<remote-host>/db
    spring.datasource.username=<username>
    spring.datasource.password=<password>
    

    如果您想将嵌入式H2用于其他所有功能,可以省略配置,因为当H2位于类路径上时,Spring Boot将为您自动配置内存中的H2。

    qa 作为活动配置文件,您将自动连接到配置的数据源。可以使用Maven配置文件选择活动弹簧配置文件。

    你不需要多个 DataSource

    推荐文章