首页 > 代码库 > SpringSide3中多数据源配置
SpringSide3中多数据源配置
applicationContext.xml中配置
下面是加载外部配置文件:application.properties
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="systemPropertiesModeName" value=http://www.mamicode.com/"SYSTEM_PROPERTIES_MODE_OVERRIDE" />>
多数据源配置:<!-- 本地数据库配置 --> <bean id="dataSourceContent" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close"> <property name="uniqueResourceName"> <value>jdbc/dataSourceContent</value> </property> <property name="xaDataSourceClassName"> <value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value> </property> <property name="xaProperties"> <props> <prop key="serverName">${jdbc.servername}</prop> <prop key="portNumber">${jdbc.portnumber}</prop> <prop key="databaseName">${jdbc.databasename}</prop> <prop key="user">${jdbc.username}</prop> <prop key="password">${jdbc.password}</prop> </props> </property> <property name="poolSize"> <value>5</value> </property> <property name="maxPoolSize"> <value>15</value> </property> <property name="testQuery"> <value>select 1</value> </property> </bean> <bean id="dataSourceIndex" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close"> <property name="uniqueResourceName"> <value>jdbc/dataSourceIndex</value> </property> <property name="xaDataSourceClassName"> <value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value> </property> <property name="xaProperties"> <props> <prop key="serverName">${jdbc.servername_index}</prop> <prop key="portNumber">${jdbc.portnumber_index}</prop> <prop key="databaseName">${jdbc.databasename_index}</prop> <prop key="user">${jdbc.username_index}</prop> <prop key="password">${jdbc.password_index}</prop> </props> </property> <property name="poolSize"> <value>5</value> </property> <property name="maxPoolSize"> <value>15</value> </property> <property name="testQuery"> <value>select 1</value> </property> </bean>
Hibernate sessionFactory配置:<!-- Hibernate配置 --> <!-- 本地数据库Hibernate配置 --> <bean id="sessionFactoryContent" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSourceContent" /> <property name="namingStrategy"> <bean class="org.hibernate.cfg.ImprovedNamingStrategy" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <prop key="hibernate.format_sql">${hibernate.format_sql}</prop> <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop> <prop key="hibernate.cache.provider_configuration_file_resource_path">ehcache/ehcache-hibernate-local.xml</prop> </props> </property> <property name="packagesToScan" value=http://www.mamicode.com/"com.wiseweb.pom.entity" />>
事务管理器配置:<!-- 事务管理器配置,多数据源JTA事务--> <bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close"> <property name="forceShutdown"><value>true</value></property> </bean> <bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp"> <property name="transactionTimeout" value=http://www.mamicode.com/"300"/>>
application.properties文件:jdbc.driver=com.mysql.jdbc.Driver jdbc.servername=host jdbc.portnumber=port jdbc.databasename=databasename jdbc.url=jdbc\:mysql\://host\:port/databaseName?useUnicode\=true&zeroDateTimeBehavior\=convertToNull&characterEncoding\=utf-8 jdbc.username=username jdbc.password=password hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect #mysql version database setting jdbc.servername_index=hostjdbc.portnumber_index=port jdbc.databasename_index=databaseName jdbc.url_index=jdbc\:mysql\://host\:port/databaseName?useUnicode\=true&zeroDateTimeBehavior\=convertToNull&characterEncoding\=utf-8 jdbc.username_index=username jdbc.password_index=password #hibernate settings hibernate.show_sql=false hibernate.format_sql=false hibernate.use_second_level_cache=false hibernate.use_query_cache=false #dbcp settings dbcp.maxIdle=5 dbcp.maxActive=40jta.properties
com.atomikos.icatch.service=com.atomikos.icatch.standalone.UserTransactionServiceFactory com.atomikos.icatch.console_file_name = sm.out com.atomikos.icatch.log_base_name = smlog.log com.atomikos.icatch.tm_unique_name = com.atomikos.spring.jdbc.tm com.atomikos.icatch.serializable_logging=false
SpringSide3中多数据源配置
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。