1.转自:https://blog.csdn.net/u013802160/article/details/51815077
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" 4 xmlns:context="http://www.springframework.org/schema/context" 5 xmlns:mvc="http://www.springframework.org/schema/mvc" 6 xsi:schemaLocation="http://www.springframework.org/schema/beans 7 http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 8 http://www.springframework.org/schema/context 9 http://www.springframework.org/schema/context/spring-context-3.1.xsd 10 http://www.springframework.org/schema/mvc 11 http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"> 12 13 <!-- 自动扫描 --> 14 <context:component-scan base-package="com.goshop" /> 15 16 <!-- 引入配置文件 --> 17 <bean id="propertyConfigurer" 18 class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 19 <property name="location" value="classpath:jdbc.properties"></property> 20 </bean> 21 22 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" 23 destroy-method="close"> 24 <property name="driverClassName" value="${driver}" /> 25 <property name="url" value="${url}" /> 26 <property name="username" value="${username}" /> 27 <property name="password" value="${password}" /> 28 <!-- 初始化连接大小 --> 29 <property name="initialSize" value="${initialSize}"></property> 30 <!-- 连接池最大数量 --> 31 <property name="maxActive" value="${maxActive}"></property> 32 <!-- 连接池最大空闲 --> 33 <property name="maxIdle" value="${maxIdle}"></property> 34 <!-- 连接池最小空闲 --> 35 <property name="minIdle" value="${minIdle}"></property> 36 <!-- 获取连接最大等待时间 --> 37 <property name="maxWait" value="${maxWait}"></property> 38 </bean> 39 40 <!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 --> 41 <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> 42 <property name="dataSource" ref="dataSource"></property> 43 <!-- 自动扫描mapping.xml文件 -->
<!-- 将configLocation去掉,换成mapperLocations则扫描所有xml配置文件 ,-->
<!-- 如果用configLocation,则可在Configuration.xml 一个一个加载实体配置文件.xml --> 44 <!-- <property name="configLocation" value="mybatis/SqlMapConfig.xml" /> --> 45 <property name="mapperLocations" value="classpath:com/goshop/mapper/*.xml"></property> 46 </bean> 47 48 <!-- DAO接口所在包名,Spring会自动查找其下的类 --> 49 <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> 50 <property name="basePackage" value="com.goshop.dao" /> 51 <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property> 52 </bean> 53 54 <!-- (事务管理)transaction manager, use JtaTransactionManager for global tx --> 55 <bean id="transactionManager" 56 class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 57 <property name="dataSource" ref="dataSource" /> 58 </bean> 59 60 </beans>
2.
<property name="dataSource" ref="dataSource"></property>
43 <!-- 自动扫描mapping.xml文件 -->
<!-- 将configLocation去掉,换成mapperLocations则扫描所有xml配置文件 ,-->
<!-- 如果用configLocation,则可在Configuration.xml 一个一个加载实体配置文件.xml -->
44 <!-- <property name="configLocation" value="mybatis/SqlMapConfig.xml" /> -->
<property name="mapperLocations" value="classpath:com/goshop/mapper/*.xml"></property>