1、直接配置数据库信息
(1)配置德鲁伊连接池
(2)引入德鲁伊连接池依赖jar包
如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property><!--驱动名称-->
<property name="url" value="jdbc.mysql://localhost:3306/school"></property><!--数据库名-->
<property name="username" value="root"></property><!--用户名-->
<property name="password" value="123"></property><!--密码-->
</bean>
</beans>
2、引入外部属性文件配置数据库连接池
(1)创建外部属性文件,properities格式文件,写数据库信息
(2)把外部properties属性文件引入到spring配置文件中
*引入context名称空间
在spring配置文件使用标签引入外部属性文件
需要创建一个配置文件jdbc.properties
prop.driverClass=com.mysql.jdbc.Driver
prop.url=jdbc.mysql://localhost:3306/school
prop.userName=root
prop.password=123
之后在xml文件中引入: