首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法找到路径PostgreSQLContainer testContainers

无法找到路径PostgreSQLContainer testContainers
EN

Stack Overflow用户
提问于 2018-11-26 12:16:22
回答 2查看 2.4K关注 0票数 4

在使用Postgres版本的试验容器时,我无法找到我的资源地图。我正在尝试类似的方法:

代码语言:javascript
复制
     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的资源

项目结构

有同样问题的人吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-11-27 19:45:18

withClasspathResourceMapping的用法是当您有一个类路径集时。在我的例子中,我没有,这个方法也不起作用。作为替代,我尝试了使用addFileSystemBind,并且工作得很好:

代码语言:javascript
复制
postgresqlContainer.addFileSystemBind(scriptsPath + File.separator + "create.sh",
                "/docker-entrypoint-initdb.d/00_create.sh",
                BindMode.READ_ONLY);
票数 2
EN

Stack Overflow用户

发布于 2018-11-29 09:27:59

withClasspathResourceMapping使用ClassLoader#getResource。这个论点与你的班级无关。相反,它使用当前类路径。就您的情况而言,它应该与以下方面一起工作:

代码语言:javascript
复制
withClasspathResourceMapping("/db/create.sh", "/docker-entrypoint-initdb.d/00_create.sh")
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53480946

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档