xml配置spring集成hibernate

前端之家收集整理的这篇文章主要介绍了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的 事务管理器 强大。

原文链接:https://www.f2er.com/xml/296759.html

猜你在找的XML相关文章