hibernate.cfg.xml - hibernate.cfg.xml路径

标签 hibernate.cfg.xml

我有一个Java项目,正在使用hibernate。这里的事情是我想将hibernate.cfg.xml文件放在“src”文件夹之外,但是当我配置该文件时,它显示FileNotFoundException。如果我把它放在src文件夹中就可以了。但是我想将java src和所有配置文件分开在单独的文件夹中。

                               root
                                |____src
                                |____conf
                                      |____mapping
                                             |____(all xml file with hibernate.cfg.xml)

SessionFactory _sessionFactory =(new Configuration())。configure(“./ conf / mapping / hibernate.cfg.xml”)。buildSessionFactory();

它显示异常...

最佳答案

将conf / mapping目录添加到CLASSPATH并加载配置文件

new Configuration().configure("/hibernate.cfg.xml").buildSessionFactory();

要不就
new Configuration().buildSessionFactory();

因为这是标准名称。

无论资源路径的开头是否存在./

关于hibernate.cfg.xml - hibernate.cfg.xml路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6031820/

相关文章:

java - "session-factory"必须匹配 "(property*,mapping*,(class-cache|collection-cache)*,event*,listener*)"

java - hibernate.cfg.xml 没有找到 hibernate.properties 文件

hibernate - 项目根文件夹中的 ConfigurationException : Could not locate cfg. xml 资源 [hibernate.cfg.xml]

java - Hibernate指定的cfg.xml文件[/src/main/resources/hibernate.cfg.xml]不存在

java - 无法在hibernate中加载hbm文件

java - 如何更改 HIbernate 配置文件 (cfg.xml) 中的驱动程序类

java - 如何为 sql server 配置 hibernate 配置文件

tomcat - xwiki 错误 : Duplicate query mapping getSpaceDocsName