org.hibernate.HibernateException: /hibernate.cfg.xml not found

前端 未结 7 996
野趣味
野趣味 2020-12-03 15:22

I\'m trying to use hibernate with spring 3 mvc but at the moment I get this exception thrown. I think I need to define my hibernate.cfg.xml somewhere, but not s

相关标签:
7条回答
  • 2020-12-03 15:54

    I have the same problem and moved hibernate.cfg.xml to the src/main/resources directory solved, it will be automatically be placed in /WEB-INF/classes.

    0 讨论(0)
  • 2020-12-03 15:56

    hibernate.cfg.xml should be in WEB-INF/classes. Alternatively, you can load it from a custom location by passing the corresponding argument to the configure(..) method.

    0 讨论(0)
  • 2020-12-03 15:56

    If you using Maven you should put file hibernate.cfg.xml in following path /src/main/java/resources/hibernate.cfg.xml in Intellij IDEA. Then, in your run application class just insert line:

    SessionFactory factory = new Configuration().configure("hibernate.cfg.xml").addAnnotatedClass().buildSessionFactory();

    0 讨论(0)
  • 2020-12-03 16:00

    Instead of placing hibernate.cfg.xml file under src/com/jr/hibernate/ directory, place it under src directory. It will then automatically appear in WEB-INF/classes directory, as mentioned by the folks here.

    0 讨论(0)
  • 2020-12-03 16:11

    hibernate.cfg.xml must be found in the root of the classpath when the webapp is started.

    If you are using maven to build the project, put hibernate.cfg.xml in the src/main/resources directory so that when you build the war package, it will be automatically be placed in /WEB-INF/classes.

    If not using maven, place the file directly in your WEB-INF/classes directory.

    0 讨论(0)
  • 2020-12-03 16:17

    In IntelliJ go to "Open Project Settings" >> Modules >> Hibernate and target your hibernate.cfg.xml file used in your project.

    0 讨论(0)
提交回复
热议问题