首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件开发 >

Spring3、Mybatis3配备整合

2012-10-05 
Spring3、Mybatis3配置整合spring配置文件如下:?xml version1.0 encodingUTF-8?beans xmlnshttp

Spring3、Mybatis3配置整合
spring配置文件如下:
<?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:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

    <!-- 数据源配置 -->
    <bean id="dataSource" value="com.ibm.db2.jcc.DB2Driver" />
        <property name="jdbcUrl"
            value="jdbc:db2://IP:50001/schema" />
        <property name="user" value="spider" />
        <property name="password" value="spider" />
        <property name="initialPoolSize" value="21" />
        <property name="minPoolSize" value="20" />
        <property name="maxPoolSize" value="30" />
        <property name="checkoutTimeout" value="10000" />
        <property name="maxIdleTime" value="60" />
    </bean>

    <!-- 事务管理器 -->
    <bean id="transactionManager"
        ref="dataSource" />
    </bean>

    <!-- 事务拦截器 -->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="save*" propagation="REQUIRED" isolation="READ_COMMITTED"
                read-only="false" />
            <tx:method name="get*" propagation="REQUIRED" isolation="DEFAULT"
                read-only="true" />
            <tx:method name="update*" propagation="REQUIRED" isolation="READ_COMMITTED"
                read-only="false" />
            <tx:method name="delete*" propagation="REQUIRED" isolation="READ_COMMITTED"
                read-only="false" />
            <tx:method name="start*" propagation="REQUIRED" isolation="READ_COMMITTED"
                read-only="false" />
            <tx:method name="stop*" propagation="REQUIRED" isolation="READ_COMMITTED"
                read-only="false" />
            <tx:method name="*" read-only="true" />
        </tx:attributes>
    </tx:advice>

    <!-- 事务核心配置 -->
    <aop:config>
        <aop:pointcut id="crawlPointcut"
            expression="execution(* com.suning.crawler.dao.*Dao.*(..))" />
        <aop:advisor id="managerTx" advice-ref="txAdvice"
            pointcut-ref="crawlPointcut" />
    </aop:config>

    <!-- 数据库连接工厂-->
    <bean id="sqlSessionFactory" />
        </property>
        <property name="mapperLocations">
            <!-- workspace
            <value>classpath*:com/**/mappers/*.mapper.xml</value>-->
            <!-- jar -->
            <value>classpath*:config/*.mapper.xml</value>
        </property>
    </bean>

    <!-- 会话 -->
    <bean id="sqlSessionTemplate" ref="sqlSessionFactory" />
    </bean>
   
</beans>
<!--
================================================
spring jar下载官网 http://www.springsource.org/download/
================================================
  -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="taskprocess">

    <!-- 保存目录到临时的临时表 -->
    <insert id="saveTempTaskTemp" parameterType="java.util.List">
        INSERT INTO TEMP_IMME_TASK(ID, TASK_ID, CATALOGUE_URL, OPERATE_TYPE, JOB_TYPE) VALUES
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.id}, #{item.taskId}, #{item.catalogueUrl}, #{item.operateType}, #{item.jobType})
        </foreach>
    </insert>

    <!--  保存目录到临时表 -->
    <insert id="saveTempTask" parameterType="java.lang.Integer">
        {call schema.SAVE_TEMP_TASK(#{id})}
    </insert>

</mapper>
<!--
================================================
mybatisjar下载官网 http://code.google.com/p/mybatis/
================================================
  -->

热点排行