微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

xml配置spring集成hibernate

<?xmlversion="1.0"encoding="UTF-8"?>
<beansxmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"
	xmlns:p="http://www.springframework.org/schema/p"xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:tx="http://www.springframework.org/schema/tx"xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
	http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
	http://www.springframework.org/schema/context
	http://www.springframework.org/schema/context/spring-context-3.0.xsd
	http://www.springframework.org/schema/mvc
	http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
	http://www.springframework.org/schema/aop
	http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
	http://www.springframework.org/schema/tx
	http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

	<!--初始化证书信息bean存储pfx信息单例-->
	<beanid="initpfx"class="com.yjm.initcert.InitX509CertInfo"
		scope="singleton"></bean>

	<!--取得返回sessionFactory对象-->
	<beanid="sessionFactory"
		class="org.springframework.orm.hibernate3.LocalSessionfactorybean">
		<propertyname="configLocation"value="classpath:hibernate.cfg.xml">
		</property>
	</bean>
	<!--
		取得hibernate的sessionfactory去封装spring自己的事务管理器事务管理器比hibernate自带的强大很多
	-->
	<beanid="transactionManager"
		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<propertyname="sessionFactory"ref="sessionFactory"/>
	</bean>
	<!--数据处理DAO类sessionfactory工厂类DAOsessionFactory单例处理-->
	<beanid="commondao"class="com.yjm.dao.CommonDAO"scope="singleton">
		<propertyname="sessionFactory"ref="sessionFactory"></property>
	</bean>

	<!--逻辑处理service类Food-->
	<beanid="foodservice"class="com.yjm.service.FoodService">
		<propertyname="commonDAO"ref="commondao"></property>
	</bean>
	<!--逻辑处理service类User-->
	<beanid="userservice"class="com.yjm.service.UserService">
		<propertyname="commonDAO"ref="commondao"></property>
	</bean>

	<!--逻辑处理service类UserInfo-->
	<beanid="userinfo"class="com.yjm.service.UserInfoService">
		<propertyname="commonDAO"ref="commondao"></property>
	</bean>

	<!--l-->

	<!--用代理类对TransactionManager进行组合切面事务管理-->
	<tx:adviceid="advice"transaction-manager="transactionManager">
		<tx:attributes>
			<tx:methodname="find*"propagation="required"read-only="true"/>
			<tx:methodname="select*"propagation="required"read-only="true"/>
			<tx:methodname="load*"propagation="required"read-only="true"/>
			<tx:methodname="get*"propagation="required"/>
			<tx:methodname="save*"propagation="required"/>
		</tx:attributes>
	</tx:advice>
	<!--定义切面-->
	<aop:config>
		<aop:pointcutexpression="execution(*com.yjm.service.*.*(..))"
			id="point"/>
		<aop:advisoradvice-ref="advice"pointcut-ref="point"/>
	</aop:config>
</beans>


sessionFactory 注入 类 认返回的是Hibernate sessionFactory 对象

用hibernate sessionFactory 封装 spring 自己的transactionManager,spring自己的事务管理器比hibernate的 事务管理器 强大。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念
xml文件介绍及使用
xml编程(一)-xml语法
XML文件结构和基本语法
第2章 包装类