在使用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的资源
项目结构

有同样问题的人吗?
发布于 2018-11-27 19:45:18
withClasspathResourceMapping的用法是当您有一个类路径集时。在我的例子中,我没有,这个方法也不起作用。作为替代,我尝试了使用addFileSystemBind,并且工作得很好:
postgresqlContainer.addFileSystemBind(scriptsPath + File.separator + "create.sh",
"/docker-entrypoint-initdb.d/00_create.sh",
BindMode.READ_ONLY);发布于 2018-11-29 09:27:59
withClasspathResourceMapping使用ClassLoader#getResource。这个论点与你的班级无关。相反,它使用当前类路径。就您的情况而言,它应该与以下方面一起工作:
withClasspathResourceMapping("/db/create.sh", "/docker-entrypoint-initdb.d/00_create.sh")https://stackoverflow.com/questions/53480946
复制相似问题