码迷,mamicode.com
首页 > 编程语言 > 详细

xml配置spring集成hibernate

时间:2015-05-18 21:12:31      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:xml配置spring集成hibernate

<?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: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信息 单例 -->
	<bean id="initpfx" class="com.yjm.initcert.InitX509CertInfo"
		scope="singleton"></bean>

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

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

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

	<!-- l -->

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


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

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


xml配置spring集成hibernate

标签:xml配置spring集成hibernate

原文地址:http://yjm199.blog.51cto.com/4408395/1652280

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!