miwaiwai

导航

统计

数据库连接池

dbcp,c3p0,druid(德鲁伊),spring.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:util="http://www.springframework.org/schema/util"
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">
<!-- 配置扫描包 -->
<context:component-scan
base-package="com.yyp.service.impl"></context:component-scan>
<context:component-scan
base-package="com.yyp.dao.impl"></context:component-scan>
<!-- 工具类加到ioc容器宏 -->
<bean class="com.yyp.util.SpringBeanHolder" />
<!-- 配置DataSource 采用spring内置的数据源,但是他没有连接池的功能 -->
<!-- 读取数据库的属性配置文件dataSource.properties -->
<context:property-placeholder
location="classpath:dataSource.properties" />
<bean id="dataSource1"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"
value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<!-- 使用dbcp数据源,这个数据源有连接池的功能,效率会更高一些 -->
<bean id="dataSource2"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="initialSize" value="5" />
<property name="maxActive" value="100" />
<property name="minIdle" value="3" />
<property name="maxIdle" value="5" />
<property name="maxWait" value="5000" />
</bean>
<!-- 德鲁伊连接池配置 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="driverClassName"
value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="initialSize" value="5" />
<property name="maxActive" value="100" />
<property name="minIdle" value="3" />
<property name="maxIdle" value="5" />
<property name="maxWait" value="5000" />
</bean>
<!-- 配置jdbcTemplate -->
<bean class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>

</bean>
</beans>

 

posted on   米歪歪  阅读(8)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 通过 API 将Deepseek响应流式内容输出到前端
· AI Agent开发,如何调用三方的API Function,是通过提示词来发起调用的吗
点击右上角即可分享
微信分享提示