报错如下所示:

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

<?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. test-event-create

    # 1 创建存储过程 /* delimiter // create procedure test() begin update test SET name = date_format(now(),'% ...

  2. sqlalchemy(二)高级用法 2

    转自:https://www.cnblogs.com/coder2012/p/4746941.html 外键以及relationship 首先创建数据库,在这里一个user对应多个address,因此 ...

  3. jq封装选项卡写法

    jq普通选项卡写法: var tabTag=$('#tabon'); var tabon=tabTag.find('li');//菜单栏 var tabCon=$(".hidden" ...

  4. settings配置与model优化

    settings配置与model优化 settings: 项目基本配置(settings.py, models.py, admin.py,  templates...).数据库操作.中间件 http: ...

  5. C++之(::)运算符详解

    ::运算符 (::)是运算符中等级最高的,作用有三种,都是左关联的,都是为了更明确自己调用的对象或者函数: 全局作用域 类作用域 命名空间作用域 1.全局作用域 #include<iostrea ...

  6. 可采用两种方法得到一个EJB对象

    (本文是转载其他人的技术文章,觉得说得挺浅显易懂,特借来学习)     在前面学习的例子中,只有一个EJB,但是对于一个真实的项目,EJB的数量可以有很多,而且EJB之间也会互相调用,那么在一个EJB ...

  7. 004-React入门概述

    一.概述 参考地址:https://reactjs.org/docs/try-react.html 1.1.本地快速体验 <!DOCTYPE html> <html> < ...

  8. Mysql查询结果导出为Excel的几种方法

    本文地址:http://www.cnblogs.com/qiaoyihang/p/6398673.html 具体原文找不到了,此篇是借鉴门户的一篇文章 方法一:查询语句直接输出语法格式: Exampl ...

  9. windows8系统安装MongoDB 2.6.3配置服务启动

    转自:http://winfan.net/655.html 1. 下载mongodb包2. 解压zip至 D:\MongoDB3. 创建目录 D:\MongoDB\data\db4. 创建日志目录 D ...

  10. Python:笔记(5)——错误、调试和测试

    Python:笔记(5)——错误.调试和测试 错误处理 1.TRY语句 这个和Java中的语法是及其相似的,catach换成except. 说明:同样,不管有没有错误,fianlly都会执行的! 补充 ...