我有一个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/