step 1:导入德鲁伊jar包,配置jdbc.properties
pros.driverClass=com.mysql.cj.jdbc.Driver
pros.url=jdbc:mysql://localhost:3306/test?serverTimezone=Asia/Shanghai
pros.userName=root
pros.password=83853649jkl
step2 :配置spring bean.xml文件
在bean.xml文件头中加入,具体参考bean.xml文件
-
xmlns:context="http://www.springframework.org/schema/context" -
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
bean.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"
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:property-placeholder location="classpath:jdbc.properties" />
<!-- 配置连接池-->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="driverClassName" value="${props.driverClass}"></property>
<property name="url" value="${props.url}"></property>
<property name="username" value="${props.username}"></property>
<property name="password" value="${props.password}"></property>
</bean>
</beans>