hibernate3和spring整合的一些方式
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="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">
<!-- 引入prperties配置文件 -->
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>classpath:jdbc.properties</value>
</property>
</bean> <bean id="dataSource" destroy-method="close"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean> <!-- 引入sessionFactory LocalSessionFactoryBean 既满足了hibernate的特点,也满足了spring容器的特点 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean> <bean id="sessionFactory2"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingDirectoryLocations">
<list>
<!--
spring容器会去该包及子包下搜索所有的映射文件
-->
<value>com/itheima11/spring/hibernate/domain</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean> <!--
引入dao和service层
-->
<bean id="classesDao" class="com.itheima11.spring.hibernate.dao.impl.ClassesDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean id="classesService" class="com.itheima11.spring.hibernate.service.impl.ClassesServiceImpl">
<property name="classesDao">
<ref bean="classesDao"/>
</property>
</bean> <!--
事务管理器
-->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<tx:advice id="tx" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" read-only="false"/>
</tx:attributes>
</tx:advice> <!--
进行aop的配置
-->
<aop:config>
<aop:pointcut
expression="execution(* com.itheima11.spring.hibernate.service.impl.*.*(..))"
id="perform"/>
<aop:advisor advice-ref="tx" pointcut-ref="perform"/>
</aop:config> <import resource="applicationContext-callback.xml"/>
</beans>
hibernate3和spring整合的一些方式的更多相关文章
- Ibatis,Spring整合(注解方式注入)
applicationContext.xml <?xml version="1.0" encoding="UTF-8"?> <beans xm ...
- spring 整合quartz的方式——简单介绍
一.继承QuartzJobBean,重写executeInternal方法 <bean name="statQuartzJob" class="org.spring ...
- 使用Spring整合Quartz轻松完成定时任务
一.背景 上次我们介绍了如何使用Spring Task进行完成定时任务的编写,这次我们使用Spring整合Quartz的方式来再一次实现定时任务的开发,以下奉上开发步骤及注意事项等. 二.开发环境及必 ...
- Spring整合MyBatis(二)Spring整合MyBatis
摘要: 本文结合<Spring源码深度解析>来分析Spring 5.0.6版本的源代码.若有描述错误之处,欢迎指正. 了解了MyBatis的独立使用过程后,我们再看看它与Spring整合的 ...
- Spring整合Quartz轻松完成定时任务
一.背景 上次我们介绍了如何使用Spring Task进行完成定时任务的编写,这次我们使用Spring整合Quartz的方式来再一次实现定时任务的开发,以下奉上开发步骤及注意事项等. 二.开发环境及必 ...
- spring 整合 mybatis 中数据源的几种配置方式
因为spring 整合mybatis的过程中, 有好几种整合方式,尤其是数据源那块,经常看到不一样的配置方式,总感觉有点乱,所以今天有空总结下. 一.采用org.mybatis.spring.mapp ...
- Spring整合Struts2框架的第二种方式(Action由Spring框架来创建)(推荐大家来使用的)
1. spring整合struts的基本操作见我的博文:https://www.cnblogs.com/wyhluckdog/p/10140588.html,这里面将spring与struts2框架整 ...
- Spring整合Struts2框架的第一种方式(Action由Struts2框架来创建)。在我的上一篇博文中介绍的通过web工厂的方式获取servcie的方法因为太麻烦,所以开发的时候不会使用。
1. spring整合struts的基本操作见我的上一篇博文:https://www.cnblogs.com/wyhluckdog/p/10140588.html,这里面将spring与struts2 ...
- Spring整合Hibernate的两种方式
在使用spring注解整合hibernate时出现"org.hibernate.MappingException: Unknown entity: com.ssh.entry.Product ...
随机推荐
- Difference Between Initialization and Assignment in C++
Initialization happens when a variable is given a value at the moment it is created. Assignment obli ...
- 在Vista或Windows 7系统上安装Sharepoint 2007
在Vista或Windows 7系统上安装Sharepoint 2007 2010-03-05 18:53:19| 分类: 技术文章|字号 订阅 SharePoint 2007 不能直接安装 ...
- ExtJs布局之border
<!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv ...
- Struts2 Convention插件的使用(4)使用@Action注解返回json数据
package com.hyy.action; import java.util.HashMap; import java.util.Map; import org.apache.struts2.co ...
- converntion
One convention that we have is to use the names of fruits and vegetables for variables(only in small ...
- 李洪强iOS开发之OC[009] -OC无参方法的声明实现和调用
- lintcode:Wiggle Sort II
Wiggle Sort II Given an unsorted array nums, reorder it such that nums[0] < nums[1] > nums[2] ...
- GSM、3G、LTE、4G
3GPP(The 3rd Generation Partnership Project)3GPP的目标是实现由2G网络到3G网络的平滑过渡,保证未来技术的后向兼容性,支持轻松建网及系统间的漫游和兼容性 ...
- switch中的default的位置
[转载]http://hi.baidu.com/dannie007zxl/item/5d0c3185577df719c3162724 有的时候,我们对身旁自认为熟悉的东西,却发现很难去给出准确的回答. ...
- hashmap理解总结
1.hashmap是通过存放对象的hash算法进行对象的存储的,其查询,put,get方法均是. 所以将对象存储进hashmap,set啥时候,要重写hashcode方法. 2.hash算法存储,查询 ...