Spring configures files for multiple data sources

Source: Internet
Author: User

<?xml version= "1.0" encoding= "UTF-8"?>
<!--Repository and Service layers--
<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:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"
xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans-4.2.xsd
Http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/spring-aop-4.2.xsd ">

<!--========================= Repository RESOURCE Definitions =========================-
<bean id= "Slave" class= "Org.apache.tomcat.jdbc.pool.DataSource" >
<property name= "Driverclassname" value= "${jdbc.mysql.driver}"/>
<property name= "url" value= "${slave.connection}"/>
<property name= "username" value= "${slave.username}"/>
<property name= "Password" value= "${slave.password}"/>
<!--Public Configuration Properties--
<property name= "maxactive" value= "/>"
<property name= "InitialSize" value= "ten"/>
<property name= "Minidle" value= "ten"/>
<property name= "jdbcinterceptors" value= "${tomcat.jdbc.pool.jdbcinterceptors}"/>
<property name= "Testwhileidle" value= "true"/>
<property name= "Testonborrow" value= "true"/>
<property name= "Validationquery" value= "Select 1"/>
<property name= "Testonreturn" value= "false"/>
<property name= "Validationinterval" value= "30000"/>
<property name= "Timebetweenevictionrunsmillis" value= "/>"
<property name= "maxwait" value= "15000"/>
<property name= "removeabandoned" value= "true"/>
<property name= "removeabandonedtimeout" value= "/>"
<property name= "logabandoned" value= "false"/>
<property name= "Minevictableidletimemillis" value= "/>"
</bean>

<bean id= "Master" class= "Org.apache.tomcat.jdbc.pool.DataSource" >
<property name= "Driverclassname" value= "${jdbc.mysql.driver}"/>
<property name= "url" value= "${master.connection}"/>
<property name= "username" value= "${master.username}"/>
<property name= "Password" value= "${master.password}"/>
<!--Public Configuration Properties--
<property name= "maxactive" value= "/>"
<property name= "InitialSize" value= "ten"/>
<property name= "Minidle" value= "ten"/>
<property name= "jdbcinterceptors" value= "${tomcat.jdbc.pool.jdbcinterceptors}"/>
<property name= "Testwhileidle" value= "true"/>
<property name= "Testonborrow" value= "true"/>
<property name= "Validationquery" value= "Select 1"/>
<property name= "Testonreturn" value= "false"/>
<property name= "Validationinterval" value= "30000"/>
<property name= "Timebetweenevictionrunsmillis" value= "/>"
<property name= "maxwait" value= "15000"/>
<property name= "removeabandoned" value= "true"/>
<property name= "removeabandonedtimeout" value= "/>"
<property name= "logabandoned" value= "false"/>
<property name= "Minevictableidletimemillis" value= "/>"
</bean>

<bean id= "Oldmemberdb" class= "Org.springframework.jdbc.datasource.DriverManagerDataSource" >
<property name= "Driverclassname" value= "Com.mysql.jdbc.Driver"/>
<property name= "url" value= "${oldmemberdb.connection}"/>
<property name= "username" value= "${oldmemberdb.username}"/>
<property name= "Password" value= "${oldmemberdb.password}"/>
</bean>


<bean id= "DataSource" class= "db. Dynamicdatasource ">
<property name= "master" ref= "master"/>
<property name= "Slaves" >
<list>
<ref bean= "Slave"/>
</list>
</property>
</bean>

<!--IBATIS3 Factory class--
<bean id= "Sqlsessionfactory" class= "Org.mybatis.spring.SqlSessionFactoryBean" >
<property name= "DataSource" ref= "DataSource"/>
<property name= "configlocation" value= "Classpath:sqlMapConfig.xml"/>
<property name= "Mapperlocations"
Value= "Classpath:/jdbc/uc/dao/*.xml"/>
<property name= "Typealiasespackage" value= "Uc.jdbc.uc.po"/>
</bean>

<bean id= "Sqlsessionfactory_1" class= "Org.mybatis.spring.SqlSessionFactoryBean" >
<property name= "DataSource" ref= "Oldmemberdb"/>
<property name= "configlocation" value= "Classpath:sqlMapConfig.xml"/>
<property name= "Mapperlocations"
Value= "Classpath:/uc/jdbc/uc/dao/testmapper.xml"/>
<property name= "Typealiasespackage" value= "Uc.jdbc.uc.po"/>
</bean>

<bean class= "Org.mybatis.spring.mapper.MapperScannerConfigurer" >
<property name= "Basepackage" value= "Uc.jdbc.uc.olddao"/>
<property name= "Sqlsessionfactorybeanname" value= "Sqlsessionfactory_1" ></property>
</bean>


<bean class= "Mapperscannerconfigurer" >
<property name= "Basepackage" value= "Uc.jdbc.uc.dao"/>
<property name= "Sqlsessionfactorybeanname" value= "Sqlsessionfactory"/>
</bean>

<!--define a single JDBC data source transaction Manager--
<bean id= "TransactionManager"
class= "Dynamicdatasourcetransactionmanager" >
<!--class= "Org.springframework.jdbc.datasource.DataSourceTransactionManager" >-
<property name= "DataSource" ref= "DataSource"/>
</bean>
<!--define transactions with @Transactional annotations--
<tx:annotation-driven transaction-manager= "Trasactionmanager"
Proxy-target-class= "true"/>

<bean id= "Transactiontemplate"
class= "Org.springframework.transaction.support.TransactionTemplate" >
<property name= "TransactionManager" ref= "TransactionManager"/>
<!--Isolation_default indicates that the database used is determined by
<property name= "Isolationlevelname" value= "Isolation_default"/>
<property name= "Propagationbehaviorname" value= "propagation_required"/>
<property name= "Timeout" value= "/>"
</bean>

<bean id= "Transactiontemplatenew"
class= "Org.springframework.transaction.support.TransactionTemplate" >
<property name= "TransactionManager" ref= "TransactionManager"/>
<!--Isolation_default indicates that the database used is determined by
<property name= "Isolationlevelname" value= "Isolation_default"/>
<property name= "Propagationbehaviorname" value= "Propagation_requires_new"/>
<property name= "Timeout" value= "/>"
</bean>

</beans>

Spring configures files for multiple data sources

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.