配置的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
谁能告诉我错在哪里。
<?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:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-2.5.xsd">
<!--===================================================================================
指定Spring配置中用到的属性文件
====================================================================================-->
<bean id="propertyConfigurer"
class="com.byd.mes.util.PropertyConfigurer">
<property name="locations" >
<list>
<!--
<value>classpath:com/byd/mes/conf/jdbc@b_wip3.properties</value>
<value>classpath:com/byd/mes/conf/jdbc@b_wip.properties</value>
<value>classpath:com/byd/mes/conf/jdbc@bmes_wip.properties</value>
-->
<value>classpath:com/byd/mes/conf/jdbc@bmes_dev.properties</value>
<value>classpath:com/byd/mes/conf/system_conf.properties</value>
</list>
</property>
</bean>
<!--===================================================================================
数据源
====================================================================================-->
<!-- 业务数据库 -->
<bean id="dataSourceORG" class="org.apache.commons.dbcp.BasicDataSource" destroy-method ="close"
p:driverClassName="${mes.org.jdbc.driver}"
p:url="${mes.org.jdbc.connectionURL}"
p:username="${mes.org.jdbc.username}"
p:password="${mes.org.jdbc.password}"
/>
<!-- 归档数据库 -->
<bean id="dataSourceODS" class="org.apache.commons.dbcp.BasicDataSource" destroy-method ="close"
p:driverClassName="${mes.ods.jdbc.driver}"
p:url="${mes.ods.jdbc.connectionURL}"
p:username="${mes.ods.jdbc.username}"
p:password="${mes.ods.jdbc.password}"
/>
<!-- 动态数据源 -->
<bean id="dataSource" class="com.byd.mes.util.datasource.DynamicDataSource">
<property name="targetDataSources">
<map>
<entry key="orgdb" value-ref="dataSourceORG"/>
<entry key="odsdb" value-ref="dataSourceODS"/>
</map>
</property>
<property name="defaultTargetDataSource" ref="dataSourceORG" />
</bean>
<!--===================================================================================
ibatis配置
====================================================================================-->
<bean id="lobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler"/>
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="configLocation">
<value>classpath:com/byd/mes/conf/sqlMapConfig_mes.xml</value>
</property>
<property name="lobHandler" ref="lobHandler"/>
</bean>
<!--===================================================================================
定义事务管理器(声明式的事务)
====================================================================================-->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource">
<ref local="dataSource" />
</property>
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" timeout="60"
read-only="false" rollback-for="Throwable" />
<tx:method name="send*" propagation="REQUIRED" timeout="60"
read-only="false" rollback-for="Throwable" />
<tx:method name="save*" propagation="REQUIRED" timeout="60"
read-only="false" rollback-for="Throwable" />
<tx:method name="delete*" propagation="REQUIRED" timeout="60"
read-only="false" rollback-for="Throwable" />
<tx:method name="update*" propagation="REQUIRED" timeout="60"
read-only="false" rollback-for="Throwable" />
<tx:method name="imp*" propagation="REQUIRED" timeout="180"
read-only="false" rollback-for="Throwable" />
<tx:method name="execute*" propagation="REQUIRED" timeout="60"
read-only="false" rollback-for="Throwable" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="interceptorPointCuts"
expression="(execution(* com.byd.mes..*ServiceImpl.*(..)))" />
<aop:advisor
advice-ref="txAdvice" pointcut-ref="interceptorPointCuts" />
</aop:config>
<!--===================================================================================
OTHER SPRING XML
====================================================================================-->
<!-- 权限 -->
<import resource="applicationContext-permission.xml" />
<!-- 动态任务 -->
<import resource="applicationContext-quartz.xml" />
<!--===================================================================================
ACTION XML
====================================================================================-->
<!-- 主数据 action -->
<import resource="action_mes_main.xml"/>
<!-- 权限action -->
<import resource="action_mes_system.xml"/>
<!-- 现场操作管理 -->
<import resource="action_mes_siteoperation.xml"/>
<!-- 仓库管理 -->
<import resource="action_mes_wm.xml"/>
<!-- 包装出货管理 -->
<import resource="action_mes_packing.xml"/>
<!-- 生成管理-->
<import resource="action_mes_production.xml"/>
<!-- 系统缓存配置-->
<import resource="cache_conf.xml"/>
<!-- 开发-->
<import resource="action_mes_dev.xml"/>
<!--===================================================================================
DAO XML
=====================================================================================-->
<!-- 主数据 dao-->
<import resource="dao_mes_main.xml" />
<!-- 权限DAO -->
<import resource="dao_mes_system.xml" />
<!-- POD模块DAO -->
<import resource="dao_mes_siteoperation.xml" />
<!-- 仓库模块DAO -->
<import resource="dao_mes_wm.xml" />
<!-- 生产管理DAO -->
<import resource="dao_mes_production.xml" />
<!-- 包装 dao-->
<import resource="dao_mes_packing.xml" />
<!-- dao_pagedesign.xml dao-->
<import resource="dao_pagedesign.xml" />
<!--===================================================================================
SERVICE XML
=====================================================================================-->
<!-- 主数据 service-->
<import resource="service_mes_main.xml" />
<!-- 权限SERVICE -->
<import resource="service_mes_system.xml" />
<!-- POD模块SERVICE -->
<import resource="service_mes_siteoperation.xml" />
<!-- 仓库模块SERVICE -->
<import resource="service_mes_wm.xml" />
<!-- 生产管理SERVICE -->
<import resource="service_mes_production.xml" />
<!-- 包装 service-->
<import resource="service_mes_packing.xml" />
<!--===================================================================================
OTHER XML
=====================================================================================-->
<!-- Applicationcontext应用Bean -->
<bean id="beanFactory" class="com.byd.mes.util.BeanFactory"
p:propertyConfigurer-ref ="propertyConfigurer"/>
<!--===================================================================================
系统标准功能点 XML解析服务类
=====================================================================================-->
事务拦截器配置有问题,
transactionManager_1没有配置