【问题标题】:hibernate.cfg.xml not found (intellij/maven)未找到 hibernate.cfg.xml (intellij/maven)
【发布时间】:2020-05-05 19:40:34
【问题描述】:

所以我在 intellij 中运行一个休眠项目,但是由于我添加了一个模块信息,休眠没有找到配置。 enter image description here

正如您在上面看到的,配置位于应该位于 maven 项目中的资源中。 删除模块信息不会改变任何东西。 这是我的模块信息:

module ProjektRechnungsprogramm {
requires java.persistence;
requires java.sql;
requires org.hibernate.orm.core;
requires java.naming;
requires net.bytebuddy;
requires org.hibernate.commons.annotations;}

即使我尝试 getClass.getResource("hibernate.cfg.xml") 它也会返回 null。

【问题讨论】:

    标签: java hibernate maven


    【解决方案1】:

    您已将配置放在 utils 目录中,因此请使用获取资源

    getClass.getResource("Utils/hibernate.cfg.xml")

    【讨论】:

    • 是的,只是为了测试目的。如果它位于根目录或 Utils 目录中,则没有区别。如果我没记错的话,它甚至不应该对 getResource 产生影响
    • @NielYorck 你可以使用 getClass.getResource("Utils/hibernate.cfg.xml") 访问配置文件
    • 没有。也返回 null。
    • @NielYorck 如果您可以添加有问题的代码,我可以帮助您。
    • 在这一行失败:registry = new StandardServiceRegistryBuilder().configure().build();配置应该会自动找到配置
    猜你喜欢
    • 2017-09-07
    • 2012-01-02
    • 2011-06-23
    • 2015-02-07
    • 1970-01-01
    • 2013-01-24
    • 2016-06-11
    • 1970-01-01
    相关资源
    最近更新 更多