ConfigurationException:找不到项目根文件夹中的cfg.xml资源[hibernate.cfg.xml] [英] ConfigurationException: Could not locate cfg.xml resource [hibernate.cfg.xml] in project root folder

查看:1017
本文介绍了ConfigurationException:找不到项目根文件夹中的cfg.xml资源[hibernate.cfg.xml]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目根文件夹中有 hibernate.cfg.xml 文件。



如果我运行的应用程序包含:

  SessionFactory sessionFactory = new 。配置()配置()buildSessionFactory()。 

它在 configure()方法中崩溃并发送以下消息:

lockquote

无法找到cfg.xml资源[hibernate.cfg.xml]


输出

  2016 12:04:59 PM org.hibernate.Version logVersion 
INFO:HHH000412:Hibernate Core {5.2.0.Final}
Jun 17,2016 12:04:59 PM org.hibernate.cfg。环境< clinit>
INFO:HHH000205:从资源hibernate.properties加载的属性:{hibernate.connection.driver_class = org.h2.Driver,hibernate.service.allow_crawling = false,hibernate.max_fetch_depth = 5,hibernate.dialect = org.hibernate .dialect.H2Dialect,hibernate.format_sql = true,hibernate.generate_statistics = true,hibernate.connection.username = sa,hibernate.connection.url = jdbc:h2:mem:db1; DB_CLOSE_DELAY = -1; LOCK_TIMEOUT = 10000,hibernate。 bytecode.use_reflection_optimizer = false,hibernate.connection.password = ****,hibernate.connection.pool_size = 5}
org.hibernate.cfg.Environment buildBytecodeProvider
INFO:HHH000021:字节码提供程序名称:javassist
org.hibernate.internal.util.config.ConfigurationException:无法找到org.hibernate.boot中的cfg.xml资源[hibernate.cfg.xml]
.cfgxml.internal.ConfigLoader.loadConfigXmlResource(ConfigLoader.java:53)
at org.hibernate.boot.registry.StandardServiceRegistryBuilder.configure(StandardService RegistryBuilder.java:163)
在org.hibernate.cfg.Configuration.configure(Configuration.java:258)
在org.hibernate.cfg.Configuration.configure(Configuration.java:244)
at okjHibernateTest.main(HibernateTest.java:22)


解决方案

hibernate.cfg.xml 文件应该被移至 src 文件夹。


I have the hibernate.cfg.xml file in the project root folder.

If I run an application containing:

SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();

it crashes in the configure() method with the following message:

Could not locate cfg.xml resource [hibernate.cfg.xml]

Output:

Jun 17, 2016 12:04:59 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.0.Final}
Jun 17, 2016 12:04:59 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000205: Loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=org.h2.Driver, hibernate.service.allow_crawling=false, hibernate.max_fetch_depth=5, hibernate.dialect=org.hibernate.dialect.H2Dialect, hibernate.format_sql=true, hibernate.generate_statistics=true, hibernate.connection.username=sa, hibernate.connection.url=jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;LOCK_TIMEOUT=10000, hibernate.bytecode.use_reflection_optimizer=false, hibernate.connection.password=****, hibernate.connection.pool_size=5}
Jun 17, 2016 12:04:59 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
org.hibernate.internal.util.config.ConfigurationException: Could not locate cfg.xml resource [hibernate.cfg.xml]
    at org.hibernate.boot.cfgxml.internal.ConfigLoader.loadConfigXmlResource(ConfigLoader.java:53)
    at org.hibernate.boot.registry.StandardServiceRegistryBuilder.configure(StandardServiceRegistryBuilder.java:163)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:258)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:244)
    at o.k.j.HibernateTest.main(HibernateTest.java:22)

解决方案

The hibernate.cfg.xml file should be moved to src folder.

这篇关于ConfigurationException:找不到项目根文件夹中的cfg.xml资源[hibernate.cfg.xml]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆