配置流程:
配置datasource
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass"> <value>#[dsp.jdbc.driverClassName]</value> </property> <property name="jdbcUrl"> <value>#[dsp.jdbc.url]</value> </property> <property name="user"> <value>#[dsp.jdbc.username]</value> </property> <property name="password"> <value>#[dsp.jdbc.password]</value> </property> <property name="maxPoolSize"> <value>#[dsp.jdbc.maxPoolSize]</value> </property> <property name="minPoolSize"> <value>#[dsp.jdbc.minPoolSize]</value> </property> <property name="initialPoolSize"> <value>#[dsp.jdbc.initialPoolSize]</value> </property> <property name="idleConnectionTestPeriod"> <value>#[dsp.jdbc.idleConnectionTestPeriod]</value> </property> <property name="maxIdleTime"> <value>#[dsp.jdbc.maxIdleTime]</value> </property> </bean> <bean id="dataSourceSsp" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass"> <value>#[ssp.jdbc.driverClassName]</value> </property> <property name="jdbcUrl"> <value>#[ssp.jdbc.url]</value> </property> <property name="user"> <value>#[ssp.jdbc.username]</value> </property> <property name="password"> <value>#[ssp.jdbc.password]</value> </property> <property name="maxPoolSize"> <value>#[ssp.jdbc.maxPoolSize]</value> </property> <property name="minPoolSize"> <value>#[ssp.jdbc.minPoolSize]</value> </property> <property name="initialPoolSize"> <value>#[ssp.jdbc.initialPoolSize]</value> </property> <property name="idleConnectionTestPeriod"> <value>#[ssp.jdbc.idleConnectionTestPeriod]</value> </property> <property name="maxIdleTime"> <value>#[ssp.jdbc.maxIdleTime]</value> </property> </bean>
配置SqlSessionFactory
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean" lazy-init="false"> <property name="configLocation" value="classpath:rousseau-mybatis-config.xml"></property> <property name="dataSource" ref="dataSource" /> </bean> <bean id="sqlSessionFactorySsp" class="org.mybatis.spring.SqlSessionFactoryBean" lazy-init="false"> <property name="configLocation" value="classpath:rousseau-ssp-mybatis-config.xml"></property> <property name="dataSource" ref="dataSourceSsp" /> </bean>
配置Mapper文件扫描
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="sqlSessionFactory" ref="sqlSessionFactory"/> <property name="basePackage" value="com.zmeng.rinascimento.rousseau.mapper.dsp" /> </bean> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="sqlSessionFactory" ref="sqlSessionFactorySsp"/> <property name="basePackage" value="com.zmeng.rinascimento.rousseau.mapper.ssp" /> </bean>