报错如下所示:

私以为是配置文件出现问题了。

<?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中时报错的更多相关文章

  1. [原创]java WEB学习笔记77:Hibernate学习之路---Hibernate 版本 helloword 与 解析,.环境搭建,hibernate.cfg.xml文件及参数说明,持久化类,对象-关系映射文件.hbm.xml,Hibernate API (Configuration 类,SessionFactory 接口,Session 接口,Transaction(事务))

    本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...

  2. hibernate.cfg.xml文件的配置模板和不同数据库的配置參数

    (1)hibernate.cfg.xml文件的配置模板 <?xml version="1.0" encoding="UTF-8"?> <!DO ...

  3. 使用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目录下.

  4. 5 -- Hibernate的基本用法 --4 2 hibernate.properties文件与hibernate.cfg.xml文件

    hibernate.properties : project\etc\hibernate.properties hibernate.cfg.xml : project\etc\hibernate.cf ...

  5. Hibernate 连接MySQL/SQLServer/Oracle数据库的hibernate.cfg.xml文件

    用Hibernate配置连接数据库可以方便我们对POJO的操作,节省了很多时间和代码.下面就分别说明连接不同数据库需要在hibernate.cfg.xml做的配置. 需要数据库驱动包可以点击这里下载: ...

  6. 读取hibernate.cfg.xml文件

    new Configuration().configure().buildSessionFactory() new Configuration()默认是读取hibernate.properties 所 ...

  7. hibernate.cfg.xml文件连接mySql、Oracle、SqlServer配置

    1.连接mySql,文件配置如下: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibe ...

  8. hibernate.cfg.xml文件的说明

    <?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hi ...

  9. Hibernate之通过hibernate.cfg.xml配置文件访问数据库的例子

    hibernate.cfg.xml文件内容: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE ...

随机推荐

  1. 什么是Python?Python的设计哲学?如何获取/升级Python?

    Python? Python(英国发音:/ˈpaɪθən/ 美国发音:/ˈpaɪθɑːn/) Python的创始人为吉多·范罗苏姆(Guido van Rossum). 1989年的圣诞节期间,吉多· ...

  2. 浅谈 Python 的 with 语句(转)

    add by zhj: 上下文管理器是对try-except-finally的再封装而已,只能算是优化代码这一级别的feature 原文:http://www.ibm.com/developerwor ...

  3. MySQL之表的约束

    一 介绍 约束条件与数据类型的宽度一样,都是可选参数 作用:用于保证数据的完整性和一致性主要分为: PRIMARY KEY (PK) 标识该字段为该表的主键,可以唯一的标识记录 FOREIGN KEY ...

  4. Motion camera 真人动作捕捉器

    视频1 http://v.youku.com/v_show/id_XNzk4MDA2MTg4.html 视频2 http://v.youku.com/v_show/id_XNzk4MDA5OTIw.h ...

  5. 五分钟学会 Kotlin 语法

    为什么使用Kotlin 项目一期在收尾了终于有时间折腾了,一个多月以来Kotlin从入门到现在,坚持用来开发的切身感受.因为语法与Java的区别挺大的一开始很想放弃,如果不是因为项目在使用,想必很少人 ...

  6. CentOS 6.5 QtCreator启动时 dbus-1的错误解决方法

    启动QtCreator提示:dbus_connection_can_send_type的错误, QString::arg: Argument missing: 无法解析dbus_connection_ ...

  7. Linux环境配置全局jdk和局部jdk并生效

    全局jdk配置: 1.root用户登录 2.进入opt目录,新建java文件夹 cd  /opt mkdir java  上传jdk7u79linuxx64.tar.gz包到java文件夹并解压 jd ...

  8. nodejs多核处理

    前言大家都知道nodejs是一个单进程单线程的服务器引擎,不管有多么的强大硬件,只能利用到单个CPU进行计算.所以,有人开发了第三方的cluster,让node可以利用多核CPU实现并行. 随着nod ...

  9. JS 原生JS 判断滚动条滑动到底部

    window.addEventListener("scroll", function(event) { var scrollTop = document.documentEleme ...

  10. JavaScript与Java数据类型的区别

    今天开始正式认真学习js,虽然在平常j2ee开发中也经常用到JS但并不精通,这次随笔记下js与Java数据类型的不同之处 Number 与java不同,js作为弱类型语言即使在浮点数与整数上也未作明确 ...