xml spring multi数据源,multi profile配置
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了xml spring multi数据源,multi profile配置相关的知识,希望对你有一定的参考价值。
<?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:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd">
<beans profile="dev">
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:jdbc/test.properties"/>
</bean>
</beans>
<beans profile="online">
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:jdbc/online.properties"/>
</bean>
</beans>
<beans profile="offline">
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:jdbc/offline.properties"/>
</bean>
</beans>
<beans profile="dev,offline,online">
<!-- For DSP -->
<bean id="dspDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${jdbc.dsp.driverClassName}"/>
<property name="jdbcUrl" value="${jdbc.dsp.url}"/>
<property name="user" value="${jdbc.dsp.username}"/>
<property name="password" value="${jdbc.dsp.password}"/>
<property name="maxPoolSize" value="${jdbc.dsp.maxPoolSize}"/>
<property name="minPoolSize" value="${jdbc.dsp.minPoolSize}"/>
<property name="initialPoolSize" value="${jdbc.dsp.initialPoolSize}"/>
<property name="idleConnectionTestPeriod" value="${jdbc.dsp.idleConnectionTestPeriod}"/>
<property name="maxIdleTime" value="${jdbc.dsp.maxIdleTime}"/>
</bean>
<!-- For RCV -->
<bean id="rcvDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${jdbc.rcv.driverClassName}"/>
<property name="jdbcUrl" value="${jdbc.rcv.url}"/>
<property name="user" value="${jdbc.rcv.username}"/>
<property name="password" value="${jdbc.rcv.password}"/>
<property name="maxPoolSize" value="${jdbc.rcv.maxPoolSize}"/>
<property name="minPoolSize" value="${jdbc.rcv.minPoolSize}"/>
<property name="initialPoolSize" value="${jdbc.rcv.initialPoolSize}"/>
<property name="idleConnectionTestPeriod" value="${jdbc.rcv.idleConnectionTestPeriod}"/>
<property name="maxIdleTime" value="${jdbc.rcv.maxIdleTime}"/>
</bean>
</beans>
<beans profile="test">
<jdbc:embedded-database id="dataSource" type="H2">
<jdbc:script location="classpath:sql/db_setting.sql"/>
<jdbc:script location="classpath:sql/schema-plan_info.sql"/>
<jdbc:script location="classpath:sql/schema-user_info.sql"/>
<jdbc:script location="classpath:sql/schema-archive_user_cost.sql"/>
<jdbc:script location="classpath:sql/schema-user_pre_cost.sql"/>
<jdbc:script location="classpath:sql/schema-plan_pre_cost.sql"/>
</jdbc:embedded-database>
<alias name="dataSource" alias="rcvDataSource"/>
<alias name="dataSource" alias="dspDataSource"/>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg ref="dataSource"/>
</bean>
</beans>
<beans>
<!--DSP part-->
<bean id="dspSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean" lazy-init="false">
<property name="configLocation" value="classpath:mybatis-config.xml"/>
<property name="dataSource" ref="dspDataSource"/>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="dspSqlSessionFactory"/>
<property name="basePackage" value="com.zmeng.rinascimento.pascal.mapper.dsp"/>
</bean>
<bean id="dspTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dspDataSource"/>
</bean>
<tx:annotation-driven transaction-manager="dspTransactionManager"/>
<!--RCV part-->
<bean id="rcvSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean" lazy-init="false">
<property name="configLocation" value="classpath:mybatis-config.xml"/>
<property name="dataSource" ref="rcvDataSource"/>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="rcvSqlSessionFactory"/>
<property name="basePackage" value="com.zmeng.rinascimento.pascal.mapper.rcv"/>
</bean>
<bean id="rcvTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="rcvDataSource"/>
</bean>
<tx:annotation-driven transaction-manager="rcvTransactionManager"/>
</beans>
</beans>
以上是关于xml spring multi数据源,multi profile配置的主要内容,如果未能解决你的问题,请参考以下文章
RequestContextHolder.getRequestAttributes()null - Spring Security + Multi Tenant [关闭]
Creating a Multi Module Spring Boot Project
python读取xml文件报错ValueError: multi-byte encodings are not supported
RequestContextHolder.getRequestAttributes() null - Spring Security + Multi Tenant [关闭]
python读取xml文件报错ValueError: multi-byte encodings are not supported