wyuxiao729
2011-11-07 10:06
浏览 208
已采纳

spring+mybatis多数据源配置问题,谁能帮我分析一下问题出在哪儿

配置的XML文件

[code="xml"]

<?xml version="1.0" encoding="UTF-8"?>
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">

<!-- 数据源配置 
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>  
    <property name="url" value="jdbc:oracle:thin:@221.237.x.x:1521:orcl"/>  
    <property name="username" value="iptv_dev"/>  
    <property name="password" value="just4iptv"/>
</bean>
-->

<bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource">
    <property name="driver" value="oracle.jdbc.driver.OracleDriver" />   
    <property name="driverUrl" value="jdbc:oracle:thin:@221.237.x.x:1521:orcl" />   
    <property name="user" value="user" />   
    <property name="password" value="aaaaa" /> 
    <property name="prototypeCount" value="5"/>  
    <property name="maximumConnectionCount" value="100"/> 
    <property name="minimumConnectionCount" value="5"/> 
    <property name="maximumActiveTime" value="10000"/> 
    <property name="trace" value="true"/> 
    <property name="verbose" value="true"/>  
 </bean>

 <!-- IP网管数据源接口 -->
<bean id="dataSource_1" class="org.logicalcobwebs.proxool.ProxoolDataSource">
    <property name="driver" value="oracle.jdbc.driver.OracleDriver" />   
    <property name="driverUrl" value="jdbc:oracle:thin:@61.139.x.x:1521:orcl" />   
    <property name="user" value="user" />   
    <property name="password" value="aaaa" /> 
    <property name="prototypeCount" value="5"/>  
    <property name="maximumConnectionCount" value="100"/> 
    <property name="minimumConnectionCount" value="5"/> 
    <property name="maximumActiveTime" value="10000"/> 
    <property name="trace" value="true"/> 
    <property name="verbose" value="true"/>  
 </bean>


<!-- 事务管理 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />
</bean>

<bean id="transactionManager_1" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource_1" />
</bean>

<!-- 使用spring annotation自动扫描配置 -->  
<context:component-scan base-package="com.zznode.iptvs" />
<!-- 自动注入 -->
<context:annotation-config />


<!-- 使用spring annotation自动事务配置
<tx:annotation-driven transaction-manager="transactionManager"/>
-->


<!-- SqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <!-- 根据实际情况修改或添加多个 -->
    <property name="typeAliasesPackage" value="com.zznode.iptvs.diagnosis.entity,com.zznode.iptvs.test.entity,com.zznode.iptvs.intf.entity,com.zznode.iptvs.diagnosis.intf.entity" />
</bean>

<!-- SqlSessionFactory -->
<bean id="sqlSessionFactory_1" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource_1" />
    <!-- 根据实际情况修改或添加多个 -->
    <property name="typeAliasesPackage" value="com.zznode.iptvs.manage.entity" />
</bean>

<!-- Mapper自动扫描配置 -->
<bean name="scan" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <!-- 根据实际情况修改或添加多个 -->
    <property name="basePackage" value="com.zznode.iptvs.monitor.dao,com.zznode.iptvs.test.dao,com.zznode.iptvs.diagnosis.dao,com.zznode.iptvs.expert.dao,com.zznode.iptvs.diagnosis.intf.dao" />
    <property name="sqlSessionFactory" ref="sqlSessionFactory" />
</bean>

<bean name="scan_1" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <!-- 根据实际情况修改或添加多个 -->
    <property name="basePackage" value="com.zznode.iptvs.manage.dao" />
    <property name="sqlSessionFactory" ref="sqlSessionFactory_1" />
</bean>

<!-- 事务拦截器配置 -->
<bean id="transactionInterceptor"
    class="org.springframework.transaction.interceptor.TransactionInterceptor">
    <property name="transactionManager">
        <ref bean="transactionManager" />
    </property>
    <property name="transactionAttributes">
        <props>
            <prop key="add*">PROPAGATION_REQUIRED,-Exception</prop>
            <prop key="delete*">PROPAGATION_REQUIRED,-Exception</prop>
            <prop key="update*">PROPAGATION_REQUIRED,-Exception</prop>
        </props>
    </property>
</bean>

<!-- 采用自动BeanNameAutoProxyCreator实现事务拦截代理的自动配置         基于服务的事务管理       -->
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
    <property name="beanNames">
        <list>
            <value>*Service*</value>
        </list>
    </property>
    <property name="interceptorNames">
        <list>
            <value>transactionInterceptor</value>
        </list>
    </property>
</bean>

[/code]

目前配置好后。我对sqlSessionFactory_1下面包的数据进行读写时,还是读写的是sqlSessionFactory下面的数据。也就是数据源dataSource而不是数据源dataSource_1
谁能告诉我错在哪里。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题