spring hibernate.cfg.xml not found

走远了吗. 提交于 2020-01-22 02:17:15

问题


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

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


回答1:


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.

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.

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.



来源:https://stackoverflow.com/questions/33715803/spring-hibernate-cfg-xml-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!