我使用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”之类的路径?谢谢!
答案 0 :(得分:0)
您必须在source目录中放入默认包(无论它的名称是什么),以便Eclipse在编译时将其复制到目标文件夹,这使得它在执行应用程序时可以在类路径的根目录下使用。