Spring—Hibernate
1.家jar包
2配置applicationContext与xxx.hbm.xml(根据需要决定是否配置hibernate.hbm.xml)
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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 一、配置数据库连接池 ComboPooledDataSource -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<!-- Connection properties -->
<property name="driverClass" value="${driverClass}" />
<property name="jdbcUrl" value="${jdbcUrl}" />
<property name="user" value="${username}" />
<property name="password" value="${password}" />
<!-- Pool properties-->
<property name="minPoolSize" value="2" />
<property name="maxPoolSize" value="10" />
<property name="maxStatements" value="50" />
<property name="idleConnectionTestPeriod" value="3000" />
<property name="loginTimeout" value="300" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<!--方式一
直接从外部读取配置文件,此时需要有相应的Hibernate。hbm.xml,xxx.hbm.xml配置,容器找不到的配置会在这个路径去找 -->
<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
<!-- 方式二:
若没有外部Hibernate.hbm.xml配置文件,只能在自身文件查找,但相应的xxx.hbm.xml(bean对应的文件)还需添加。
注意:再配置hibernate其他属性的时候在名字前要加上hibernate,否则配置无效
<property name="mappingResources">
<list>
引入xxx.hbm.xml
<value>com/donghua/jdbc_dao/User.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props >
配置hibernate的其他配置
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
-->
</bean>
<bean id="userDao" class="com.donghua.jdbc_dao.UserDao">
<property name="factory" ref="sessionFactory"></property>
</bean>
</beans>
Spring—Hibernate的更多相关文章
- Struts+Spring+Hibernate项目的启动线程
在Java Web项目中,经常要在项目开始运行时启动一个线程,每隔一定的时间就运行一定的代码,比如扫描数据库的变化等等.要实现这个功能,可以现在web.xml文件中定义一个Listener,然后在这个 ...
- SSH面试题(struts2+Spring+hibernate)
struts2 + Spring +hibernate Hibernate工作原理及为什么要用? 原理: 1.读取并解析配置文件 2.读取并解析映射信息,创建SessionFactory ...
- SSH(Struts2+Spring+Hibernate)框架搭建流程<注解的方式创建Bean>
此篇讲的是MyEclipse9工具提供的支持搭建自加包有代码也是相同:用户登录与注册的例子,表字段只有name,password. SSH,xml方式搭建文章链接地址:http://www.cnblo ...
- Struts,spring,hibernate三大框架的面试
Struts,spring,hibernate三大框架的面试 1.Hibernate工作原理及为什么要用? 原理: 1.读取并解析配置文件 2.读取并解析映射信息,创建SessionFactory 3 ...
- struts2+spring+hibernate(SSH)框架的搭建和总结
SSH框架:struts2+spring+hibernate,是目前较流行的一种Web应用程序开源集成框架,用于构建灵活.易于扩展的多层Web应用程序. struts2+spring+hibernat ...
- SSH框架简化(struts2+spring+hibernate)
目的: 通过对ssh框架有了基础性的学习,本文主要是使用注解的方式来简化ssh框架的代码编写. 注意事项: 1.运行环境:Windows 8-64位,Eclipse(开发工具),jdk1.8.0_91 ...
- 用eclipse搭建SSH(struts+spring+hibernate)框架
声明: 本文是个人对ssh框架的学习.理解而编辑出来的,可能有不足之处,请大家谅解,但希望能帮助到大家,一起探讨,一起学习! Struts + Spring + Hibernate三者各自的特点都是什 ...
- Struts2 + Spring + Hibernate
Struts2 + Spring + Hibernate整合. 使用的是无配置方法进行SSH的整合,struts-convertion plugin + spring annotation + hib ...
- Spring MVC+Spring +Hibernate配置事务,但是事务不起作用
最近做项目,被一个问题烦恼了很久.使用Spring MVC+Spring +Hibernate开发项目,在使用注解配置事务管理,刚开始发现无论如何数据库都无法更新,但是可以从数据库查询到数据.怀疑是配 ...
- spring+hibernate常见异常集合
spring+hibernate出错小结: (1)java.lang.NoClassDefFoundError: org/hibernate/context/CurrentSessionContext ...
随机推荐
- 【每天一个Linux命令】12. Linux中which命令的用法
which 用来查看可执行文件的位置. 1.命令格式: which 可执行文件名称 2.命令功能: which指令会在PATH变量指定的路径中,搜索某个系统命令的位置,并且返回第一个搜索结果. 3. ...
- python教程,文章list
http://www.2cto.com/kf/web/Python/ http://www.v2ex.com/go/python http://www.sharejs.com/codes/python ...
- Unix/Linux环境C编程入门教程(10) SUSE Linux EnterpriseCCPP开发环境搭建
安装SUSE企业版以及搭建C/C++开发环境 1. SUSELinux Enterprise是一款服务器操作系统,异常稳定. 2.设置虚拟机类型. 3.选择稍后安装操作系统. 4.选择SUS ...
- UNIX网络编程卷1 时间获取程序server UDP 协议无关
本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie /** * UDP 协议无关 调用 getaddrinfo 和 udp_server **/ ...
- WPF基础——继承
1) 可以定义继承自其他类的类,关系是“父类/子类”.子类继承父类的成员(不严谨) 2) 定义语法“class子类:父类”,不指定父类则父类为Object,.Net中所有类都直接或者间接继承自Ob ...
- UCML破解
最近一直加班,好久没更新了.无良的产品经理一直催着修改功能,本想把活带回家做..结果...公司就一个UCML的加密狗...闹心....想办法破解: 1.狗复制,这个没搞过,某宝上有帮忙复制的,联系了一 ...
- BZOJ 1217: [HNOI2003]消防局的设立( 贪心 )
一个简单的贪心, 我们只要考虑2个消防局设立的距离为5时是最好的, 因为利用最充分. 就dfs一遍, 再对根处理一下就可以了. 这道题应该是SGU某道题的简化版...这道题距离只有2, 树型dp应该也 ...
- JavaScript 的 Promise
先看这个 http://www.html5rocks.com/zh/tutorials/es6/promises/#toc-api [JavaScript Promise 浏览器支持的Promise ...
- clear:both后margin-top不起作用
如: <div style="float:left;">float:left</div> <div style="clear:both;ma ...
- HTML本地存储,localstorg的应用实例
<!doctype html> <html> <head> <meta charset="UTF-8"> <title> ...