Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使hibernate cfgxml文件可定位?_Java_Spring_Hibernate - Fatal编程技术网

Java 如何使hibernate cfgxml文件可定位?

Java 如何使hibernate cfgxml文件可定位?,java,spring,hibernate,Java,Spring,Hibernate,一切都在正确的位置,但我每次都会遇到相同的错误,即cfg.xml未找到,我也更改了目录,但根本没有为我工作 我有xml基本配置 <web-app> <display-name>Archetype Created Web Application</display-name> <servlet> <servlet-name>spring</servlet-name> <servlet-class&g

一切都在正确的位置,但我每次都会遇到相同的错误,即cfg.xml未找到,我也更改了目录,但根本没有为我工作

我有xml基本配置

<web-app>
  <display-name>Archetype Created Web Application</display-name>
  <servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>
      org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

</web-app> 


Web应用程序创建的原型
春天
org.springframework.web.servlet.DispatcherServlet
春天
/
spring-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:ctx="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-2.5.xsd ">


    <ctx:annotation-config></ctx:annotation-config>
    <ctx:component-scan base-package="com.inov8"></ctx:component-scan>

</beans>

默认情况下,Hibernate配置文件必须位于根文件夹(src)的名称下

hibernate.cfg.xml
如果要重命名它或更改位置,必须在Configure()方法中给出它的路径


欢迎来到stackoverflow。请阅读并改进您的问题。提示,不要让人们点击链接来获取概述,而是包含实际代码而不是屏幕截图(后者将变得不可读)。请包括你的spirng配置,它包含错误。谢谢你的指导,以后我会应用这些东西。再次请添加代码而不是链接。您的控制器有缺陷请删除加载中的
src/main/resources
部分(它将从类路径的根目录加载)。另外,您不应该这样做,而是使用Spring中的
LocalSessionFactoryBean
配置xml中的sessionfactory,然后注入它。感谢您的回复,但我也尝试了这个。遗憾的是,它不起作用。
src/main/resources
是类路径的根。将其置于
src
将使其无法检测。
Configuration configuration = new Configuration().configure("your hibernate.cfg.xml path");