将hibernate.cfg.xml文件都放到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" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
"> <!-- 配置c3p0连接池 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<!-- 注入属性值 -->
<property name="driverClass" value="com.mysql.jdbc.Driver"></property>
<property name="jdbcUrl" value="jdbc:mysql:///spring_day04"></property>
<property name="user" value="root"></property>
<property name="password" value=""></property>
</bean> <!-- sessionFactory的创建交给spring管理 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<!-- 指定使用hibernate核心配置文件中,没有数据库配置,数据库配置在spring里面配置,注入dataSource -->
<property name="dataSource" ref="dataSource"></property> <!-- 指定使用hibernate核心配置文件 -->
<!-- <property name="configLocations" value="classpath:hibernate.cfg.xml"></property> --> <!-- 配置hibernate基本信息 -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
</props>
</property> <!-- 配置映射文件引入 -->
<property name="mappingResources">
<list>
<value>cn/itcast/entity/User.hbm.xml</value>
</list>
</property> </bean> <!-- 第一步 配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<!-- 注入sessionFactory -->
<property name="sessionFactory" ref="sessionFactory">
</property>
</bean> <!-- 第二步 开启事务注解 -->
<tx:annotation-driven transaction-manager="transactionManager" /> <!-- 配置action对象 -->
<bean id="userAction" class="cn.itcast.action.UserAction" scope="prototype">
<!-- 注入service -->
<property name="userService" ref="userService"></property>
</bean> <!-- 创建service对象 -->
<bean id="userService" class="cn.itcast.service.UserService">
<!-- 注入dao 接口 = 实现类对象 -->
<property name="userDao" ref="userDaoImpl">
</property>
</bean> <!-- 创建实现类对象 -->
<bean id="userDaoImpl" class="cn.itcast.dao.UserDaoImpl">
<property name="hibernateTemplate" ref="hibernateTemplate"></property>
</bean> <!-- 创建hibernateTemplate对象 -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate5.HibernateTemplate">
<!-- 注入sessionFactory -->
<property name="sessionFactory" ref="sessionFactory">
</property>
</bean> </beans>
项目中的index.jsp可以加载。
但是不知为何当配置文件变成下面的样子时,程序就正常运行了。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
"> <!-- 配置c3p0连接池 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<!-- 注入属性值 -->
<property name="driverClass" value="com.mysql.jdbc.Driver"></property>
<property name="jdbcUrl" value="jdbc:mysql:///spring_day04"></property>
<property name="user" value="root"></property>
<property name="password" value=""></property>
</bean> <!-- sessionFactory的创建交给spring管理 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<!-- 指定使用hibernate核心配置文件中,没有数据库配置,数据库配置在spring里面配置,注入dataSource -->
<property name="dataSource" ref="dataSource"></property> <!-- 指定使用hibernate核心配置文件 -->
<!-- <property name="configLocations" value="classpath:hibernate.cfg.xml"></property> -->
<!-- 配置hibernate基本信息 -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
</props>
</property> <!-- 配置映射文件引入 -->
<property name="mappingResources">
<list>
<value>cn/itcast/entity/User.hbm.xml</value>
</list>
</property> </bean> <!-- 第一步 配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<!-- 注入sessionFactory -->
<property name="sessionFactory" ref="sessionFactory">
</property>
</bean> <!-- 第二步 开启事务注解 -->
<tx:annotation-driven transaction-manager="transactionManager"/> <!-- 配置action对象 -->
<!-- <bean id="userAction" class="cn.itcast.action.UserAction" scope="prototype">
注入service
<property name="userService" ref="userService"></property>
</bean> 创建service对象
<bean id="userService" class="cn.itcast.service.UserService">
注入dao 接口 = 实现类对象
<property name="userDao" ref="userDaoImpl">
</property>
</bean> 创建实现类对象
<bean id="userDaoImpl" class="cn.itcast.dao.UserDaoImpl">
<property name="hibernateTemplate" ref="hibernateTemplate"></property>
</bean> 创建hibernateTemplate对象
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate5.HibernateTemplate">
注入sessionFactory
<property name="sessionFactory" ref="sessionFactory">
</property>
</bean> --> <!-- 引入其他spring配置文件 -->
<import resource="classpath:user.xml"/> </beans>
将hibernate.cfg.xml文件都放到spring中时报错的更多相关文章
- [原创]java WEB学习笔记77:Hibernate学习之路---Hibernate 版本 helloword 与 解析,.环境搭建,hibernate.cfg.xml文件及参数说明,持久化类,对象-关系映射文件.hbm.xml,Hibernate API (Configuration 类,SessionFactory 接口,Session 接口,Transaction(事务))
本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...
- hibernate.cfg.xml文件的配置模板和不同数据库的配置參数
(1)hibernate.cfg.xml文件的配置模板 <?xml version="1.0" encoding="UTF-8"?> <!DO ...
- 使用hibernate读取hibernate.cfg.xml文件时碰到这个错误org.hibernate.internal.util.config.ConfigurationException: Could not locate cfg.xml resource [/HibernateTest/src/hibernate.cfg.xml]
我的问题在于把hibernate.cfg.xml文件放置在某个包中了,hibernate.cfg.xml文件需要放置在src目录下.
- 5 -- Hibernate的基本用法 --4 2 hibernate.properties文件与hibernate.cfg.xml文件
hibernate.properties : project\etc\hibernate.properties hibernate.cfg.xml : project\etc\hibernate.cf ...
- Hibernate 连接MySQL/SQLServer/Oracle数据库的hibernate.cfg.xml文件
用Hibernate配置连接数据库可以方便我们对POJO的操作,节省了很多时间和代码.下面就分别说明连接不同数据库需要在hibernate.cfg.xml做的配置. 需要数据库驱动包可以点击这里下载: ...
- 读取hibernate.cfg.xml文件
new Configuration().configure().buildSessionFactory() new Configuration()默认是读取hibernate.properties 所 ...
- hibernate.cfg.xml文件连接mySql、Oracle、SqlServer配置
1.连接mySql,文件配置如下: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibe ...
- hibernate.cfg.xml文件的说明
<?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hi ...
- Hibernate之通过hibernate.cfg.xml配置文件访问数据库的例子
hibernate.cfg.xml文件内容: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE ...
随机推荐
- delphi中 ExecSQL 与 open
对于不用返回结果集的要用execsql反之则用open;insert ,update,delete就要用到execsql;select就要用open 说得对,例子:with query1 do clo ...
- 巨蟒python全栈开发-第9天 初识函数
一.今日主要内容总览(重点) 1.什么是函数? f(x)=x+1 y=x+1 函数是对功能或者动作的封装2.函数的语法和定义 def 函数名(): 函数体 调用:函数名()3.关于函数的返回值 ret ...
- hdu 1677 Nested Dolls【贪心解嵌套娃娃问题】
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1677 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- contos7 mongodb安装教程
通过yum安装mongodb 1.创建文件mongodb.repo文件, cd /etc/yum.repos.d/ vi mongodb.repo 复制如下代码: [mongodb-org-3.4] ...
- 跳出NSDate
感觉任何语言关于时间的格式化处理,时区的处理都是多的,最近被NSDate的各种问题坑了好久 先看看关于NSDate自己的问题 1.NSDate NSDate获取当前时间 NSDate *date=[N ...
- 原!tomcat启动超时(打印了几行日志,后面没了。也不报错,处于启动状态,直到超时)
项目框架:spring+struts2+mybatis 今天优化代码,改了一堆mybatis dao和xml文件,启动项目时,就出现如标题描述的状况:打印了几行日志,后面就不打印了,也不报错,处于启动 ...
- C#__ 模拟鼠标单击事件
首先要用到的引用有 [DllImport("User32")] public extern static void mouse_event(int dwFlags, int dx, ...
- JavaScript历史和标准
不管新手老手, 学门语言如果不简单了解这门语言谁创立的, 什么时候, 现在由谁来维护, 规范在哪? 总感觉, 少了点什么, 我就是这样. 历史 1994年美国网景(Netscape)公司发布自己的浏览 ...
- Django-进阶之路--信号
Model 到目前为止,当我们的程序涉及到数据库相关操作时,我们一般都会这么搞: 创建数据库,设计表结构和字段 使用 MySQLdb 来连接数据库,并编写数据访问层代码 业务逻辑层去调用数据访问层执行 ...
- 28. Implement strStr()(KMP字符串匹配算法)
Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle ...