gpt4 book ai didi

java - Play Framework 找不到 hibernate.cfg.xml

转载 作者:行者123 更新时间:2023-11-30 04:30:24 25 4
gpt4 key购买 nike

我是 Play 框架的新手。我正在将一个项目从 struts2 迁移到 Play,该项目使用 Hibernate 进行 ORM。我有一个名为 HibernateConfig 的单例类,它加载 hibernate 配置,这是我收到以下错误的地方。

 In C:\Users\user\IdeaProjects\projectname\app\data\HibernateConfig.java at line 27. [HibernateException: /hibernate.cfg.xml not found] 
private static SessionFactory sessionFactory;


private HibernateConfig (){}

23 public static SessionFactory getSessionFactory ()
24 {

25 if (sessionFactory == null)
26 {

27 sessionFactory = new Configuration ().configure().buildSessionFactory();
28 return sessionFactory;
29 }
30 else

31 return sessionFactory;
}

这就是我的项目结构:

app -> controllers -> application controller class
app -> models -> model classes
app -> data -> HibernateConfig.java
app -> views -> html files
app -> hibernate.cfg.xml

应用程序.conf

Database configuration

db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost/dbname"
db.default.user=root
db.default.password=""

我知道问题是当我调用 new Configuration ().configure().buildSessionFactory() 时没有找到 hibernate.cfg.xml,但我不知道它必须放在 Play 中的哪个位置才能访问。 (你们也可以批评我的方法,并让我知道我是否以错误的方式处理这个问题)

最佳答案

将 hibernate.cfg.xml 文件添加到 conf 文件夹的根目录中,这应该可以解决问题。

关于java - Play Framework 找不到 hibernate.cfg.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14776167/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com