簡體   English   中英

如何使用TestContainers + Spring Boot + oracle-xe

[英]How to use TestContainers + Spring Boot + oracle-xe

我嘗試將測試容器與Oracle-XE模塊和Spring Boot結合使用,到目前為止,當我啟動測試時,遇到了異常:

Caused by: java.lang.IllegalArgumentException: JDBC URL matches jdbc:tc: prefix but the database or tag name could not be identified

在我的src/test/application.properties ,我將url datatasource聲明為:

spring.datasource.url=jdbc:tc:oracle-xe://somehostname:someport/databasename?TC_INITSCRIPT=schema-test.sql

為了指示要為oracle-xe testcontainers.properties ,我在src/test/resources創建了文件testcontainers.properties

oracle.container.image=oracleinanutshell/oracle-xe-11g:1.0.0

您知道如何進行這項工作嗎?

它與MySQL完美配合使用,並帶有數據源url:

spring.datasource.url=jdbc:tc:mysql:5.6.23://somehostname:someport/databasename?TC_INITSCRIPT=schema-test.sql

您可以創建一個測試配置類,以使用oracle xe容器配置重新定義數據源bean。

public class OracleIT  {

    @ClassRule
    public static OracleContainer oracleContainer = new OracleContainer();

    @BeforeAll
    public static void startup() {
        oracleContainer.start();
    }

    @TestConfiguration
        static class OracleTestConfiguration {

            @Bean
            DataSource dataSource() {
                HikariConfig hikariConfig = new HikariConfig();
                hikariConfig.setJdbcUrl(oracleContainer.getJdbcUrl());
                hikariConfig.setUsername(oracleContainer.getUsername());
                hikariConfig.setPassword(oracleContainer.getPassword());

                return new HikariDataSource(hikariConfig);
            }
      }

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM