gpt4 book ai didi

java - 找不到路径 PostgreSQLContainer testContainers

转载 作者:行者123 更新时间:2023-11-29 12:16:05 25 4
gpt4 key购买 nike

我在使用 Test Containers 时找不到我的资源映射, 在 Postgres 版本中。我正在尝试类似的东西:

     private static PostgreSQLContainer postgresqlContainer = new PostgreSQLContainer("postgres")
.withDatabaseName(DATABASE_NAME)
.withUsername(USER)
.withPassword(PASSWORD);

@ClassRule
@BeforeAll
public static void initContainer() {
postgresqlContainer.withExposedPorts(5432);

postgresqlContainer.withClasspathResourceMapping("../../../../../../../create.sh",
"/docker-entrypoint-initdb.d/00_create.sh",
BindMode.READ_ONLY);
postgresqlContainer.start();
}

但是,我找不到该文件。我什至尝试将脚本 create.sh 包含在同一目录中,但找不到:

java.lang.IllegalArgumentException: 路径为 ../../../../../../../create.sh 的资源在这些类加载器中找不到

项目结构

enter image description here

有人遇到同样的问题吗?

最佳答案

withClasspathResourceMapping 的用法是当您设置了类路径时。就我而言,我没有,而且这种方法不起作用。作为替换,我尝试使用 addFileSystemBind 并且工作得很好:

postgresqlContainer.addFileSystemBind(scriptsPath + File.separator + "create.sh",
"/docker-entrypoint-initdb.d/00_create.sh",
BindMode.READ_ONLY);

关于java - 找不到路径 PostgreSQLContainer testContainers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53480946/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com