新手在做Spring和Hibernate的整合,我的Spring的配置文件是这么写的:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">
   
    <!-- 配置C3P0连接池 -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
        <property name="driverClass" value="com.mysql.jdbc.Driver"/>
        <property name="jdbcUrl" value="jdbc:mysql:///springHibernate"/>
        <property name="user" value="root"/>
        <property name="password" value="123"/>
    </bean>
   
    <!-- 把SessionFactory交给Spring管理 -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <!-- 因为 hibernate.cfg.xml中没有配置数据库信息,数据库配置在Spring里面,所以要注入dataSource-->
        <property name="dataSource" ref="dataSource"/>
       
        <!-- 指定使用Hibernate核心配置文件 -->
        <property name="configLocations" value="classpath:hibernate.cfg.xml"/>
    </bean>

<bean id="userAction" class="com.action.UserAction"></bean>
</beans>

百度之后发现了问题,看到高人的指点后改了这么一个配置,马上正常运行。

原来:
        <property name="configLocations" value="classpath:hibernate.cfg.xml"/>

改为:

<!-- 指定使用Hibernate核心配置文件 -->
        <property name="configLocations" value="classpath:/hibernate.cfg.xml"/>

原话是这么说的:

Did you try classpath:/services.xml? The leading slash means to pull the resource from the root of the classpath. Without it, the file is expected to be in the package of whatever class is loading it (which I admit I don't know what that would be in this case).

主要的斜杠意味着将资源从类路径的根中拉出。没有它这个文件被期望放在装入它的任何类的包中(我承认我不知道在这种情况下会是什么)。



Causes for java.io.FileNotFoundException: class path resource [hibernat.xml] cannot be opened becaus相关推荐

  1. java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened becaus

    今天在学Spring的时候遇到一个问题, 配置文件applicationContext.xml找不到,很是郁闷啊.文件明明在这,却找不到这种问题大多数是因为文件路径的不对引起的. 首先我的我的配置文件 ...

  2. 解决java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does no

    解决java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does no ...

  3. java.io.FileNotFoundException: class path resource [springmvc.xml] cannot be opened

    一般来说路径问题. 我检查了web.xml的行,发现我设置的是固定的springmvc,但我实际命名为springMVC,当然报错. 其实报错了通过耐心翻译很容易看出问题,path resource ...

  4. java.io.FileNotFoundException class path resource [xxx.xml] cannot be opened

    没有找到xxx.xml,首先确定你项目里有这个文件吗,如果没有请添加,或者你已经存在配置文件,只是名字不是xxx.xml,请改正名字.此外还要注意最好把xxx.xml加入到classpath里,就是放 ...

  5. Caused by: java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be ope

    1.错误描述 java.lang.IllegalStateException: Failed to load ApplicationContextat org.springframework.test ...

  6. nested exception is java.io.FileNotFoundException: class path resource [springmvc.xml] cannot be ope

    根据 提示 ,逐步解决bug,逐层推进:比如,有一个错是IOException异常,Springmvc.xml找不到,就需要去找下是否有配置文件,如果有,怎么回事?第二次再深入发现是target下没有 ...

  7. maven异常解决 java.io.FileNotFoundException: class path resource [applicationContext_*.xml]

    经过查阅得知 出现这种FIleNotFoundException 原因无非两点: 1.路径配置错误 2.编译有问题,文件不存在 具体方法解决请参考https://blog.csdn.net/hanxu ...

  8. java.io.FileNotFoundException: class path resource [com/wisely/highlight_spring4/ch2/aware/text.txt]

    maven+spring在加载配置文件时报错: java.io.FileNotFoundException: class path resource [com/wisely/highlight_spr ...

  9. java.io.FileNotFoundException: class path resource引发的问题

    FileNotFoundExeception引发的问题 出现的报错方式 java.io.FileNotFoundException: class path resource [D:/workspace ...

最新文章

  1. 练习1: Python基本语法元素 (第1周)
  2. 【技术解决方案】RTP_UDP传输过程中数据丢失的解决方案
  3. C++基础知识(一)—— C++程序结构
  4. 手势在c语言的作用,手势态度在人际交往中的重要性
  5. 聊聊领域分析与业务建模
  6. django之视图函数
  7. (转)SQL Server当中生成一定范围的随机数
  8. idea创建j2ee_IntelliJ IDEA 2018 Community(社区版)创建J2EE项目+Tomcat9部署
  9. 中职计算机课例分析,中学信息技术课教学案例分析
  10. Windows下用cmd命令安装及卸载服务
  11. 无纸化办公软件app 快用这款科学处理办公事宜的便签
  12. python三角网格代码_三角剖分算法(delaunay)
  13. SuperMemo POJ - 3580
  14. Ubuntu使用小教程02——服务器上安装ubuntu桌面版(新手向)
  15. 51单片机学习笔记——SH88F4051A
  16. oracle12免安装版配置,配置免安装版Oracle客户端
  17. Android桥方法设置GPS信号,android-GPS更新间隔更快,信号良好?
  18. 使用WebBrowser控件实现打印 去掉 页眉和页脚
  19. 服务器dnf虚拟机多开吃显存吗,安卓模拟器多开对显卡有没有什么要求?
  20. [2021 icas]PPG-BASED SINGING VOICE CONVERSION WITH ADVERSARIAL REPRESENTATION LEARNING

热门文章

  1. mediawiki 简易的使用教程
  2. SOC课程——②——Verilog程序(明德杨代码规范)
  3. 海思NNIE开发(一):海思Hi3559AV100/Hi3519AV100 NNIE深度学习模块开发与调试记录
  4. Fluent边界条件设定方法
  5. 外贸跨境电商必备九款实用APP软件盘点,外贸人必看
  6. bpm的三个标准以及如何结合使用
  7. A1072 Gas Station (30) 最短路径djkstra算法
  8. python白月黑羽视频多线程笔记
  9. 读《品人录》——雍正
  10. Win10应用右下角小盾牌怎么解决?