使用Hibernate在Maven项目中找不到hibernate.properties

Jyoti Jadhav:

我尝试了多种方法来解决此错误(使用Maven项目)

  1. 我将hibernate.cfg.xml文件放在src文件夹中,然后得到相同的错误(找不到hibernate.properties)
  2. 我将hibernate.cfg.xml文件放在资源文件夹中,然后得到相同的错误(找不到hibernate.properties)
  3. 我将hibernate.cfg.xml文件放在webapp / WEB-INF文件夹中,然后得到相同的错误(找不到hibernate.properties)
  4. 我在hibernate.cfg.xml中编写的数据库的所有属性如下

<?xml version='1.0' encoding='UTF-8'?>  
<!DOCTYPE hibernate-configuration PUBLIC  
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"  
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">  
 
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
        <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/testdb</property>
        <property name="hibernate.connection.username">postgres</property>
        <property name="hibernate.connection.password">sql123</property>
        <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
        <property name="hbm2ddl.auto">create </property>
        <property name="show_sql">true</property>
        <property name="format_sql">true</property>
        <mapping resource="Employee-hbn.xml" />
    </session-factory>
</hibernate-configuration>
我得到的异常如下:

May 22, 2018 2:28:38 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.3.0.Final}
May 22, 2018 2:28:38 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Could not locate cfg.xml resource [/src/main/java/hibernate.cfg.xml]
error

如果您对此有解决方案,请告诉我

提前致谢....

v.ladynev:

找不到cfg.xml资源[/src/main/java/hibernate.cfg.xml]错误

这意味着Hibernate尝试hibernate.cfg.xml

/src/main/java/hibernate.cfg.xml

这是不正确的路径。

你应该:

  1. hibernate.cfg.xmlresources的文件夹。
  2. 使用Configuration configuration = new Configuration().configure()的配置。
  3. 刷新项目并检查它是否hibernate.cfg.xml位于build文件夹的根目录中。

一些解释:

Configuration configuration = new Configuration().configure()

与...相同

Configuration configuration = new Configuration().configure("hibernate.cfg.xml");

此行告诉Hibernate定位hibernate.cfg.xml在类路径的根目录中。例如,如果您构建jar此文件,则该文件应位于的根目录中jar

对于war类路径的根是WEB-INF/classes

当您将文件放入文件resources夹时,Maven会将文件夹的所有内容放入resources类路径的根目录(jar的根目录)。因此,您不会在中包含该resources文件夹,而jar只是其中的内容。

刷新项目时,IDE也会执行相同的操作。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

找不到异常hibernate.properties

在多模块Maven项目中使用相同的log4j.properties进行测试

无法在Maven Web项目中使用Commons Configuration读取config.properties

错误:克隆项目时找不到keystore.properties

在Maven项目中找不到ImmutableMap

如何在 Hibernate 中使用 application.properties 设置配置?

Spring找不到messages.properties

将log4j.properties放在Maven项目中的哪里?

如何在Spring Boot Maven项目中移动application.properties或执行外部属性

在Maven项目中运行代码...找不到类

找不到可行的替代方法-Java Maven项目中的Ruta

运行此C#项目-找不到资源文件“ Properties \ Resources.resx”。

如何使用hibernate.properties文件而不是hibernate.cfg.xml

使用Hibernate和Oracle找不到架构

找不到 Hibernate TypeBootstrapContext

Maven依赖-org.hibernate.engine.spi.SessionFactoryImplementor.getProperties()Ljava / util / Properties上的NoSuchMethodError

Maven:尝试使用依赖项将项目包含在另一个项目中时找不到工件

使用Maven的Java项目找不到资源

找不到针对Hibernate JPA项目的persistence.xml

hibernate4-maven-plugin找不到带注释的类

在eclipse项目中使用西里尔文.properties文件

android studio项目中的gradle.properties丢失

将.properties文件放在Eclipse项目中的哪里?

如何在Spring Boot项目中模拟.properties文件

父子项目中的 Application.properties

android项目中缺少ant.properties文件

在CQ5 Archtype中使用JspC时,在Maven项目中找不到global.jsp吗?

如何解决在使用Spring加载.properties文件时找不到文件?

从命令行使用Saxon找不到CatalogManager.properties