Spring与Hibernate混合编程(一)
来源:互联网 发布:淘宝天下天下网商区别 编辑:程序博客网 时间:2024/06/08 06:36
一、创建Java Web项目,创建数据库,添加Hibernate支持,使用数据库反向工程建立POJO类和DAO层代码;
二、添加Spring支持;
此时Run as>>MyEclipse Server Application时,报错:
Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListenerorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.service.UnknownUnwrapTypeException: Cannot unwrap to requested type [javax.sql.DataSource]
而且,浏览器显示404。
原因:Spring容器没有配置数据源!
要在applicationContext.xml中配置数据库信息,例如:
<?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:p="http://www.springframework.org/schema/p"xmlns:tx="http://www.springframework.org/schema/tx"xmlns:jdbc="http://www.springframework.org/schema/jdbc"xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.1.xsdhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"><bean id="dataSource"class="org.springframework.jdbc.datasource.DriverManagerDataSource"><property name="driverClassName" value="com.mysql.jdbc.Driver" /><property name="url" value="jdbc:mysql://localhost:3306/myuser?useSSL=false" /><property name="username" value="root" /><property name="password" value="admin" /></bean><bean id="sessionFactory"class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"><property name="configLocation" value="classpath:hibernate.cfg.xml"></property><property name="dataSource" ref="dataSource"></property></bean><bean id="transactionManager"class="org.springframework.orm.hibernate4.HibernateTransactionManager"><property name="sessionFactory" ref="sessionFactory" /></bean><tx:annotation-driven transaction-manager="transactionManager" /></beans>
0 0
- Spring与Hibernate混合编程(一)
- Swift与OC混合编程(一)
- myeclipse和struts2+spring+hibernate混合编程
- halcon与C#混合编程(一)打开一张图片
- halcon与C#混合编程(一)打开一张图片
- C#与C++混合编程之引用(一)
- Spring与Hibernate整合(一)
- Spring与Hibernate与Struts整合(一)配置文件
- Android studio 混合编程(一)
- C#与Matlab混合编程入门教程一:几种混合编程的方法
- Spring与Hibernate结合的细节源码分析(一)
- C++与matlab混合编程基于主成份分析算法的数值分析(一)
- OGRE 本地渲染引擎 与 C++/CLI 托管代码的混合编程(一)
- .Net ( c# ) 与 Fortran 混合编程实例(一):求线性方程组的解
- 基础知识(一)matlab与c++混合编程之环境搭建
- 基础知识(一)matlab与c++混合编程之环境搭建
- 基于汇编语言与c/c++语言混合编程的程序设计研究(一)
- Matlab与c++混合编程[一.几篇文章]
- getopt()函数获取两个以上参数的方法
- Android开发实践(五)App的登陆界面
- 第十周第十一周项目3(2)
- LeetCode 142. Linked List Cycle II
- OpenGL Transform feed back 粒子系统
- Spring与Hibernate混合编程(一)
- mysql 学习笔记4
- iOS9横屏竖屏设置
- 如何用微信支付宽带费用、wifi网费
- caffe基础介绍
- 第十一周时间项目(5)——d
- HQL总结
- ORACLE中Like与Instr模糊查询性能大比拼
- C++ 正则获取url中参数