当前位置: 代码迷 >> Java Web开发 >> spring上mybatis多数据源配置有关问题
  详细解决方案

spring上mybatis多数据源配置有关问题

热度:2190   发布时间:2013-02-25 21:08:50.0
spring下mybatis多数据源配置问题
这是我的applicationContext.xml文件

<?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"
     xmlns:jdbc="http://www.springframework.org/schema/jdbc"
     xmlns:context="http://www.springframework.org/schema/context"
     xsi:schemaLocation="
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
     http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-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">

<!-- 引入 jdbc.properties -->
<context:property-placeholder location="classpath:jdbc.properties" />

<!-- 配置数据源  -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName"  value="${jdbc.driverClass}" />
<property name="url"  value="${jdbc.url}" />
<property name="username"  value="${jdbc.username}" />
<property name="password"  value="${jdbc.password}" />
<property name="maxActive"  value="${jdbc.maxActive}" />
<property name="maxIdle"  value="${jdbc.maxIdle}" />
<property name="maxWait"  value="${jdbc.maxWait}" />
<property name="poolPreparedStatements" value="${jdbc.poolPreparedStatements}" />
<property name="defaultAutoCommit"  value="${jdbc.defaultAutoCommit}" />
<property name="removeAbandoned"  value="${jdbc.removeAbandoned}" />
<property name="removeAbandonedTimeout" value="${jdbc.removeAbandonedTimeout}" />
</bean>

    <!-- 配置 transaction 处理器 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>

<!-- 启动 ioc 注解 -->
    <context:component-scan base-package="com.brojade" />
    
    <!-- 启动 annotation 事务 -->
    <tx:annotation-driven transaction-manager="transactionManager"/>

<!-- mybatis 拦截器 -->
<bean id="mybatis_common_field_plugin" class="com.brojade.zeus.pub.base.FieldsPlugin"></bean>

<!-- mybaits 工厂类 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
  相关解决方案