本文主要是介绍Spring的dao层配置(dbcp数据库连接池),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
<?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"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"><!-- 引入jdbc属性文件 -->
<context:property-placeholder location="classpath:jdbc.properties"/><bean id="dataSource"class="org.apache.commons.dbcp2.BasicDataSource"><property name="driverClassName"value="${jdbc.driver}"/><property name="url"value="${jdbc.url}"/><property name="username"value="${jdbc.username}"/><property name="password"value="${jdbc.password}"/><property name="validationQuery" value="select 1" /><property name="testOnBorrow" value="true" /><property name="testWhileIdle" value="true"/>
</bean><!-- 配置sqlSessionFactory -->
<bean id="sqlSessionFactory"class="org.mybatis.spring.SqlSessionFactoryBean"><!-- 数据库连接池 --><property name="dataSource"ref="dataSource"/><!-- 加载Mybatis全局配置文件 --><property name="configLocation"value="classpath:SqlMapConfig.xml"/> <!-SqlMapConfig.xml这里使用注解,所以写明命名空间-><!-- 配置mybatis分页插件 --><property name="plugins"><array><bean class="com.github.pagehelper.PageInterceptor"><property name="properties"><!-- 使用默认配置 --><value></value></property></bean></array></property>
</bean><!--配置mapper扫描器-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><!-- 扫描包路径,如果需要扫描多个包中间用半角逗号隔开 --><property name="basePackage"value="com.map.mapper"></property><property name="sqlSessionFactoryBeanName"value="sqlSessionFactory"/>
</bean>
</beans>
这篇关于Spring的dao层配置(dbcp数据库连接池)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!