hibernate.cfg.xml路径

时间:2011-05-17 13:52:44

标签: 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();

显示异常......

2 个答案:

答案 0 :(得分:1)

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

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

或只是

new Configuration().buildSessionFactory();

因为这是标准名称。

无论资源路径的开头是否都没有./

答案 1 :(得分:0)

你想做的是

  • conf/mapping(使用Eclipse project build path
  • 中添加properties->javabuild path->source->add Folder
  • 然后无需在代码中精确定义hibernate配置文件 <{1}}就够了

这种操作很简单,就像一个魅力。