1.spring configuration file
<?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:p= "http://www.springframework.org/schema/p"Xmlns:context= "Http://www.springframework.org/schema/context"Xmlns:tx= "Http://www.springframework.org/schema/tx"Xmlns:mvc= "Http://www.springframework.org/schema/mvc"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsdhttp//Www.springframework.org/schema/contexthttp//www.springframework.org/schema/context/spring-context-3.1.xsdhttp//Www.springframework.org/schema/txhttp//www.springframework.org/schema/tx/spring-tx-3.2.xsdhttp//Www.springframework.org/schema/mvchttp//www.springframework.org/schema/mvc/spring-mvc-4.0.xsd "><!--automatically scanned-<context:component-scan base- Package= "com.cn"/> <!--Introduction Profile--<!--<bean id= "Propertyconfigurer"class= "Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" > <property name= "Location" value= "Classpath:jdbc.properties"/> </bean>--> <bean id= "Datasourceoracle"class= "Com.atomikos.jdbc.AtomikosDataSourceBean"Init-method= "Init" destroy-method= "close" > <property name= "uniqueresourcename" value= "Oracle_ds"/> < ;p roperty name= "Xadatasourceclassname"value= "Oracle.jdbc.xa.client.OracleXADataSource"/> <property name= "xaproperties" > <props> <prop key= "URL" >jdbc:oracle:thin:@192.168.222.1:1521:orcl</prop> <prop key= "user ">scott</prop> <prop key=" password ">orcl</prop> </props> </ property> <property name= "minpoolsize" value= "ten"/> <property name= "maxpoolsize" value= "100"/& Gt <property name= "borrowconnectiontimeout" value= ""/> <property name= "Maintenanceinterval" value= "/&G" T </bean> <bean id= "Datasourcemysql"class= "Com.atomikos.jdbc.AtomikosDataSourceBean"Init-method= "Init" destroy-method= "close" > <property name= "uniqueresourcename" value= "Mysql_ds"/> < Property Name= "Xadatasourceclassname"value= "Com.mysql.jdbc.jdbc2.optional.MysqlXADataSource"/> <property name= "xaproperties" > <props& Gt <prop key= "url" >jdbc:mysql://localhost:3306/test</prop><prop key= "User" >root</prop> <prop key= "password" ></prop> </props> </property> <property name= "minpoolsize" value= "ten"/> <property name= "Maxpoolsize" V Alue= "/> <property name=" borrowconnectiontimeout "value=" "/> <property name=" maintenance Interval "value="/> </bean> <bean id= "Sqlsessionfactoryoracle"class= "Org.mybatis.spring.SqlSessionFactoryBean" > <property name= "dataSource" ref= "Datasourceoracle"/> <!--automatically scan mapping.xml files--<property name= "mapperlocations" > <array> &L T;value>classpath:com/cn/dao/dept/deptdaomapper.xml</value> </array> </property> </bean> <bean id= "Sqlsessionfactorymysql"class= "Org.mybatis.spring.SqlSessionFactoryBean" > <property name= "dataSource" ref= "Datasourcemysql"/> & lt;! --Auto scan mapping.xml Files--<property name= "mapperlocations" > <array> <val ue>classpath:com/cn/dao/brand/branddaomapper.xml</value> </array> </property> &L T;/bean> <!--go to the DAO layer to scan the corresponding interface, the top of the interface to add mapperscan annotations--<beanclass= "Org.mybatis.spring.mapper.MapperScannerConfigurer" > <property name= "basepackage" value= "com.cn.dao.dept"/ > <property name= "sqlsessionfactorybeanname" value= "sqlsessionfactoryoracle" ></property> </bea N> <beanclass= "Org.mybatis.spring.mapper.MapperScannerConfigurer" > <property name= "basepackage" value= "Com.cn.dao.brand" /> <property name= "sqlsessionfactorybeanname" value= "Sqlsessionfactorymysql" ></property> </bea n> <!--Atomikos transaction Manager--<bean id= "Atomikostransactionmanager"class= "Com.atomikos.icatch.jta.UserTransactionManager"Init-method= "Init" destroy-method= "close" > <description>UserTransactionManager</description> < Property name= "Forceshutdown" > <value>true</value> </property> </bean> <bean id= "Atomikosusertransaction"class= "COM.ATOMIKOS.ICATCH.JTA.USERTRANSACTIONIMP" > <property name= "transactiontimeout" value= "/> </" Bean> <!--Spring transaction Manager--<bean id= "TransactionManager"class= "Org.springframework.transaction.jta.JtaTransactionManager" > <property name= "TransactionManager" ref= " Atomikostransactionmanager "/> <property name=" usertransaction "ref=" atomikosusertransaction "/> < ;p roperty name= "Allowcustomisolationlevels" value= "true"/> </bean> <!--use annotation to define a transaction, for the class to which you want to add things, simply Class plus @Transactional-<tx:annotation-driven transaction-manager= "TransactionManager"/> <!--<bean ID = "DataSource"class= "Org.apache.commons.dbcp.BasicDataSource"Destroy-method= "Close" > <property name= "driverclassname" value= "${driverclassname}"/> <property name= " URL "value=" ${url} "/> <property name=" username "value=" ${username} "/> <property name=" password "Value=" ${password} "/> <! – Initialize Connection size –> <property name= "InitialSize" value= "${initialsize}" ></property> <! – Maximum number of connection pools –> <property name= "maxactive" value= "${maxactive}" ></property> <! – Maximum Connection pool idle –> <property name= "Maxidle" value= "${maxidle}" ></property> <! – Connection Pool min Idle –> <property name= "Minidle" value= "${minidle}" ></property> <! – Get connection Max wait time –> <property name= "maxwait" value= "${maxwait}" ></property> </bean>--> <!--spring and MyBatis are seamlessly integrated, Configuration mapping files that do not require MyBatis-<!--<bean id= "Sqlsessionfactory"class= "Org.mybatis.spring.SqlSessionFactoryBean" > <property name= "dataSource" ref= "DataSource"/> &l t;! –<property name= "configlocation" value= "Classpath:mybatis-config.xml"/>–> <! – Auto Scan mapping.xml Files –> <property name= "mapperlocations" value= "Classpath:com/cn/**/*.xml" ></property> </bean>--> <!--the DAO interface package name, Spring automatically finds the class under it--<!--<beanclass= "Org.mybatis.spring.mapper.MapperScannerConfigurer" > <property name= "basepackage" value= "Com.cn.dao"/> <property name= "Sqlsessionfactorybeanname" value= "Sqlsessionfactory" ></property> </bean>--> <!--(transaction management) transaction manager, use Jtatransactionmanager forGlobal TX--<!--<bean id= "TransactionManager"class= "Org.springframework.jdbc.datasource.DataSourceTransactionManager" > <property name= "DataSource" ref= " DataSource "/> </bean>--></beans>
2. Project Structure
3.mybatis Mapping File
Multi-Data Source configuration demo based on Spring + Atomikos + mybatis