【发布时间】:2012-12-09 13:43:22
【问题描述】:
我使用 STS 并创建了 MVC 模板项目。我想使用hibernate,但我不知道把hibernate.cfg.xml放在哪里。在默认项目中,我只是将它放在 src/ 文件夹中。
static {
try {
// Create the SessionFactory from hibernate.cfg.xml
//AnnotationConfiguration
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
我知道我可以像这样严格添加 Hibernate.cfg.xml 的路径:
sessionFactory = new Configuration().configure("XXX").buildSessionFactory();
其中 XXX 是 hibernate.cfg.xml 的路径。如果我愿意,我应该把 hibernate.cfg.xml 放在哪里 使用“/hibernate.cfg.xml”之类的路径?谢谢!
【问题讨论】:
标签: hibernate spring-mvc configure hibernate.cfg.xml