2026-03-10 16:40:19 +08:00

133 lines
6.5 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd">
<!-- Mybatis -->
<!-- SqlSessionFactoryBean -->
<bean id="ssf2" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 数据库连接池 -->
<!-- 指定dataSource -->
<property name="dataSource" ref="dataSource2">
</property>
<!-- 测试的时候开启 -->
<!-- 加载Mybatis全局配置文件 -->
<!-- <property name="configLocation" value="/WEB-INF/classes/mybatis-config.xml"/> -->
<property name="configLocation" value="classpath:mybatis-config.xml"/>
<!-- 指定SQL定义文件 -->
<property name="mapperLocations">
<array>
<value>classpath:mapper/*.xml</value>
<value>classpath:mapper_3e/*.xml</value>
<value>classpath:mapper_dub/*.xml</value>
<value>classpath:mapper_univ3e/*.xml</value>
</array>
</property>
</bean>
<bean id="ssf1" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 数据库连接池 -->
<!-- 指定dataSource -->
<property name="dataSource" ref="dataSource1">
</property>
<!-- 测试的时候开启 -->
<!-- 加载Mybatis全局配置文件 -->
<!-- <property name="configLocation" value="/WEB-INF/classes/mybatis-config.xml"/> -->
<property name="configLocation" value="classpath:mybatis-config.xml"/>
<!-- 指定SQL定义文件 -->
<property name="mapperLocations">
<array>
<value>classpath:mapper_mysql/*.xml</value>
</array>
</property>
</bean>
<!-- 定义MapperScannerConfigurer 生成的Dao对象id为接口名首字母小写 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 指定Mapper接口所在包 -->
<property name="basePackage" value="com._3e.newdao,com.univ3e.newdao,com._3e.dao,com._3e.dubdao,com.univ3e.dao">
</property>
<property name="sqlSessionFactoryBeanName" value="ssf2"></property>
</bean>
<!-- 定义MapperScannerConfigurer 生成的Dao对象id为接口名首字母小写 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 指定Mapper接口所在包 -->
<property name="basePackage" value="com._3e.mysqldao">
</property>
<property name="sqlSessionFactoryBeanName" value="ssf1"></property>
</bean>
<!-- 配置一个namedParameterJdbcTemplate -->
<bean id="namedParameterJdbcTemplate2" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
<constructor-arg ref="dataSource2" />
</bean>
<bean id="transactionManager2" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource2" />
<!--指定此参数为false-->
<!-- 针对异常 Transaction rolled back because it has been marked as rollback-only 不知是否会引起其他错误-->
<property name="globalRollbackOnParticipationFailure" value="false" />
</bean>
<bean id="transactionManager1" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource1" />
<!--指定此参数为false-->
<!-- 针对异常 Transaction rolled back because it has been marked as rollback-only 不知是否会引起其他错误-->
<property name="globalRollbackOnParticipationFailure" value="false" />
</bean>
<!-- 多数据源事务处理表示mysqlservice包下的所有类的所有方法-->
<aop:config>
<aop:pointcut id="transacationPointcut2" expression="execution(* *..service*..*(..)) OR execution (* *..dao*..*(..))" />
<aop:pointcut id="transacationPointcut1" expression="execution(* *..mysqlservice*..*(..)) OR execution (* *..mysqldao*..*(..))" />
<aop:advisor advice-ref="txAdvisor2" pointcut-ref="transacationPointcut2" order="2"/>
<aop:advisor advice-ref="txAdvisor1" pointcut-ref="transacationPointcut1" order="2"/>
</aop:config>
<tx:advice id="txAdvisor2" transaction-manager="transactionManager2">
<tx:attributes>
<tx:method name="get*" read-only="true" />
<tx:method name="find*" read-only="true" />
<tx:method name="query*" read-only="true" />
<tx:method name="load*" read-only="true" />
<tx:method name="update*" propagation="REQUIRED" rollback-for="Exception" />
<tx:method name="do*" propagation="REQUIRED" rollback-for="Exception" />
<tx:method name="do*_" propagation="REQUIRES_NEW" rollback-for="Exception" />
<tx:method name="log*" propagation="REQUIRES_NEW" rollback-for="Exception" />
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
<tx:advice id="txAdvisor1" transaction-manager="transactionManager1">
<tx:attributes>
<tx:method name="get*" read-only="true" />
<tx:method name="find*" read-only="true" />
<tx:method name="query*" read-only="true" />
<tx:method name="load*" read-only="true" />
<tx:method name="update*" propagation="REQUIRED" rollback-for="Exception" />
<tx:method name="do*" propagation="REQUIRED" rollback-for="Exception" />
<tx:method name="do*_" propagation="REQUIRES_NEW" rollback-for="Exception" />
<tx:method name="log*" propagation="REQUIRES_NEW" rollback-for="Exception" />
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
</beans>