spring-db-context.xml:
<?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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.1.xsd">
<!--配置和创建jdbc数据源1 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<!-- 本地测试数据源配置 -->
<property name="url" value="jdbc:mysql://localhost:3306/fake_mid_server?useUnicode=true&characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
<property name="initialSize" value="1" /> <!-- 初始化连接 -->
<property name="maxActive" value="600" /> <!-- 连接池的最大数据库连接数,设为0表示无限制 -->
<property name="maxIdle" value="20" /> <!-- 没有人用连接的时候,最大闲置的连接个数,设置为0时,表示没有限制 -->
<property name="minIdle" value="1" /> <!-- 没有人用连接的时候,最小闲置的连接个数制 -->
</bean>
<!-- myibatis配置,使其支持注解和配置文件形式 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:mybatis.xml" />
<property name="typeAliasesPackage" value="com.afmobi.model.manager" />
<property name="mapperLocations" value="classpath:mybatis-mapping/*mapper.xml" />
</bean>
<bean name="mapperScannerConfigurer"
class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.afmobi.mapper.manager" />
<property name="sqlSessionFactory" ref="sqlSessionFactory"></property>
</bean>
<!--配置和创建jdbc数据源2 -->
<bean id="dataSource2" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<!-- 本地测试数据源配置 -->
<property name="url" value="jdbc:mysql://localhost:3306/sale_statistics?useUnicode=true&characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
<property name="initialSize" value="1" /> <!-- 初始化连接 -->
<property name="maxActive" value="600" /> <!-- 连接池的最大数据库连接数,设为0表示无限制 -->
<property name="maxIdle" value="20" /> <!-- 没有人用连接的时候,最大闲置的连接个数,设置为0时,表示没有限制 -->
<property name="minIdle" value="1" /> <!-- 没有人用连接的时候,最小闲置的连接个数制 -->
</bean>
<!-- myibatis配置,使其支持注解和配置文件形式 -->
<bean id="sqlSessionFactory2" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource2" />
<property name="configLocation" value="classpath:mybatis.xml" />
<property name="typeAliasesPackage" value="com.afmobi.model.operation" />
<property name="mapperLocations" value="classpath:operation-mapping/*mapper.xml" />
</bean>
<bean name="mapperScannerConfigurer2"
class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.afmobi.mapper.operation" />
<property name="sqlSessionFactory" ref="sqlSessionFactory2"></property>
</bean>
<!-- 使用spring全注解扫描services层 -->
<context:component-scan base-package="com.afmobi.service" />
<context:annotation-config />
</beans>
本文出自 “重新来学JAVA” 博客,请务必保留此出处http://3131854.blog.51cto.com/3121854/1441687