ssm框架中的配置文件

本文介绍如何在Spring框架中配置并使用阿里Druid数据库连接池,包括配置文件applicationContext.xml的内容详解,自动扫描组件,加载属性文件,设置连接池参数,以及整合事务管理和JdbcTemplate。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>

<context:annotation-config /> <!--开启注解-->

<context:component-scan base-package="com.hzx"></context:component-scan>  <!--自动扫描包-->

<!-- 加载jdbc.properties文件 -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="classpath:jdbc.properties"/>
</bean>
<!-- 阿里 druid 数据库连接池 -->  
  <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close">
	<!-- 数据库基本信息配置 -->
	<property name="url" value="${url}" />
	<property name="username" value="${username}" />
	<property name="password" value="${password}" />
	<property name="driverClassName" value="${driverClassName}" />
	<!-- 最大并发连接数 -->
	<property name="maxActive" value="${maxActive}" />
	<!-- 初始化连接数量 -->
	<property name="initialSize" value="${initialSize}" />
	<!-- 配置获取连接等待超时的时间 -->
	<property name="maxWait" value="${maxWait}" />
	<!-- 最小空闲连接数 -->
	<property name="minIdle" value="${minIdle}" />
</bean>  

<!-- 注入jdbcTemplate -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    <property name="dataSource" ref="dataSource" />
</bean>


<!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource"/>
</bean>

<!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
<tx:annotation-driven transaction-manager="transactionManager"/>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值