找不到spring hibernate.cfg.xml [英] spring hibernate.cfg.xml not found

查看:84
本文介绍了找不到spring hibernate.cfg.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Configuration configuration = new Configuration().configure("hibernate.cfg.xml");

我在src /中的配置文件。我仍然有这个错误。有人会发现我的错误。

My configuration file in src/. still i got this error. can some one spot my mistake.

推荐答案

您使用标准目录布局的maven,因此它会编译它在 src / main / java ,并复制在 src / main / resources 下找到的内容。您的配置文件不是任何类型的资源 test 路径。它很接近,但它并不在其中,它需要maven来处理它。

You're using maven with the standard directory layout, so it'll compile the stuff it finds under src/main/java, and copy the stuff it finds under src/main/resources. Your config file is not in any type of source, resource, or test path. It's close, but it's not in any of them, and it needs to be for maven to do something with it.

为了让你加载它,它需要被复制到你的目标目录,所以它必须在maven工作的目录之一中。在这种情况下,它需要位于 src / main / resources 中,以便将其复制到目标/ classes目录。

In order for you to load it, it needs to be copied to your target directory, so it must be in one of the directories maven works with. In this case it needs to be in src/main/resources so that it's copied to the target/classes directory.

现在,我不知道配置对象是什么,或者它来自哪里,但是当配置文件位于正确的位置时,它将成为类路径中的资源,而不是文件系统上的文件,因此您可能必须改变你加载它的方式。我会尝试你有第一个,它不起作用尝试'classpath:hibernate.cfg.xml'并看看你如何去。如果它不起作用,我们需要更多的信息来解决这个问题。

Now, I have no idea what that configuration object is, or where it came from, but the config file when it's in the right place will be a resource on the classpath, not a file on the filesystem, so you may have to change the way you're loading it. I'd try what you have first, and it that doesn't work try 'classpath:hibernate.cfg.xml' and see how you go. We'd need a lot more information to fix this for you if it doesn't work.

这篇关于找不到spring hibernate.cfg.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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