[java两个数据库同步]SpringMVC配置双数据源实现一个java项目同时连接两个数据库的方法
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了[java两个数据库同步]SpringMVC配置双数据源实现一个java项目同时连接两个数据库的方法,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4970字,纯文字阅读大概需要8分钟。
内容图文
<beansxmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:cache="http://www.springframework.org/schema/cache"
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:jms="http://www.springframework.org/schema/jms"xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:oxm="http://www.springframework.org/schema/oxm"
xmlns:p="http://www.springframework.org/schema/p"xmlns:task="http://www.springframework.org/schema/task"
xmlns:tx="http://www.springframework.org/schema/tx"xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/cachehttp://www.springframework.org/schema/cache/spring-cache-3.1.xsd
http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/jdbchttp://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
http://www.springframework.org/schema/jeehttp://www.springframework.org/schema/jee/spring-jee-3.1.xsd
http://www.springframework.org/schema/jmshttp://www.springframework.org/schema/jms/spring-jms-3.1.xsd
http://www.springframework.org/schema/langhttp://www.springframework.org/schema/lang/spring-lang-3.1.xsd
http://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/oxmhttp://www.springframework.org/schema/oxm/spring-oxm-3.1.xsd
http://www.springframework.org/schema/taskhttp://www.springframework.org/schema/task/spring-task-3.1.xsd
http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/utilhttp://www.springframework.org/schema/util/spring-util-3.1.xsd">
<context:annotation-config/>
<context:component-scanbase-package="com"></context:component-scan>
<beanclass="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<propertyname="locations">
classpath:com/resource/config.properties <beanid="dataSourceOne"class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<propertyname="driverClass"value="${dbOne.jdbc.driverClass}"/>
<propertyname="jdbcUrl"value="${dbOne.jdbc.url}"/>
<propertyname="user"value="${dbOne.jdbc.user}"/>
<propertyname="password"value="${dbOne.jdbc.password}"/>
<propertyname="initialPoolSize"value="${dbOne.jdbc.initialPoolSize}"/>
<propertyname="minPoolSize"value="${dbOne.jdbc.minPoolSize}"/>
<propertyname="maxPoolSize"value="${dbOne.jdbc.maxPoolSize}"/>
<beanid="dataSourceTwo"class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<propertyname="driverClass"value="${dbTwo.jdbc.driverClass}"/>
<propertyname="jdbcUrl"value="${dbTwo.jdbc.url}"/>
<propertyname="user"value="${dbTwo.jdbc.user}"/>
<propertyname="password"value="${dbTwo.jdbc.password}"/>
<propertyname="initialPoolSize"value="${dbTwo.jdbc.initialPoolSize}"/>
<propertyname="minPoolSize"value="${dbTwo.jdbc.minPoolSize}"/>
<propertyname="maxPoolSize"value="${dbTwo.jdbc.maxPoolSize}"/>
<beanid="dynamicDataSource"class="com.core.DynamicDataSource">
<propertyname="targetDataSources">
<mapkey-type="java.lang.String">
<entryvalue-ref="dataSourceOne"key="dataSourceOne">
<entryvalue-ref="dataSourceTwo"key="dataSourceTwo">
<propertyname="defaultTargetDataSource"ref="dataSourceOne">
<beanid="sessionFactory"class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<propertyname="dataSource"ref="dynamicDataSource"/>
<propertyname="hibernateProperties">
<propkey="hibernate.dialect">org.hibernate.dialect.MySQLDialect
<propkey="hibernate.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext
<propkey="hibernate.show_sql">false
<propkey="hibernate.format_sql">true
<propkey="hbm2ddl.auto">create
<propertyname="packagesToScan">
com.po <beanid="transactionManager"class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<propertyname="sessionFactory"ref="sessionFactory"/>
<tx:adviceid="txAdvice"transaction-manager="transactionManager">
<tx:methodname="add*"propagation="REQUIRED"/>
<tx:methodname="save*"propagation="REQUIRED"/>
<tx:methodname="update*"propagation="REQUIRED"/>
<tx:methodname="delete*"propagation="REQUIRED"/>
<tx:methodname="*"read-only="true"/>
[java两个数据库同步]SpringMVC配置双数据源实现一个java项目同时连接两个数据库的方法
标签:ssi red 数据源 property text conf ceo epo show
本文系统来源:https://www.cnblogs.com/sqlserver-mysql/p/12723938.html
内容总结
以上是互联网集市为您收集整理的[java两个数据库同步]SpringMVC配置双数据源实现一个java项目同时连接两个数据库的方法全部内容,希望文章能够帮你解决[java两个数据库同步]SpringMVC配置双数据源实现一个java项目同时连接两个数据库的方法所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。