首页 > 编程语言 > 详细

Mybaits整合Spring

时间:2014-04-01 08:47:44      阅读:507      评论:0      收藏:0      [点我收藏+]

<?xml version="1.0" encoding="UTF-8"?>

<beans default-autowire="byName"

      xmlns="http://www.springframework.org/schema/beans"

      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-3.1.xsd

           http://www.springframework.org/schema/tx

           http://www.springframework.org/schema/tx/spring-tx.xsd

           http://www.springframework.org/schema/aop

           http://www.springframework.org/schema/aop/spring-aop.xsd"

      xmlns:tx="http://www.springframework.org/schema/tx"

      xmlns:aop="http://www.springframework.org/schema/aop">


   <!-- 配置系统的数据源 -->

   <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">

       <property name="driverClassName" value="com.mysql.jdbc.Driver"/>

       <property name="url" value="jdbc:mysql://localhost:3306/testdb"/>

       <property name="username" value="root"/>

       <property name="password" value="leizm"/>

   </bean>


   <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">

       <property name="configLocation" value="classpath:mybatis-config.xml"/>

       <property name="mapperLocations" value="classpath:/com/lavasoft/demo/entity/*.xml"/>

       <property name="dataSource" ref="dataSource"/>

   </bean>


   <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">

       <constructor-arg ref="sqlSessionFactory"/>

   </bean>


   <!-- 事务管理器配置,单数据源事务 -->

   <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

       <property name="dataSource" ref="dataSource"/>

   </bean>


   <!-- 配置那些类的方法进行事务管理 -->

   <aop:config>

       <aop:pointcut id="executeService" expression="execution(* com.lavasoft.*.service..*(..))"/>

       <aop:advisor pointcut-ref="executeService" advice-ref="txAdvice"/>

   </aop:config>


   <!-- 配置事务特性 ,配置以get、find、query开始的方法,事务传播特性为required -->

   <tx:advice id="txAdvice" transaction-manager="transactionManager">

       <tx:attributes>

           <tx:method name="select*" read-only="true"/>

           <tx:method name="get*" read-only="true"/>

           <tx:method name="load*" read-only="true"/>

           <tx:method name="find*" read-only="true"/>

           <tx:method name="query*" read-only="true"/>

           <tx:method name="read*" read-only="true"/>

           <tx:method name="sync*"/>

           <tx:method name="*" propagation="REQUIRED" rollback-for="java.lang.Exception"/>

       </tx:attributes>

   </tx:advice>


   <bean id="personDAO" class="com.lavasoft.demo.dao.PersonDAO"/>

   <bean id="extinfoDAO" class="com.lavasoft.demo.dao.ExtinfoDAO"/>

   <bean id="personSV" class="com.lavasoft.demo.service.PersonSVImpl"/>


</beans>


本文出自 “熔 岩” 博客,请务必保留此出处http://lavasoft.blog.51cto.com/62575/1387743

Mybaits整合Spring,布布扣,bubuko.com

Mybaits整合Spring

原文:http://lavasoft.blog.51cto.com/62575/1387743

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!