Step 1: Import the druid JAR package and configure 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
Copy the code
Step2: configure the spring bean.xml file
To the bean.xml file header, refer to the bean.xml file
-
xmlns:context="http://www.springframework.org/schema/context" Copy the code
-
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd Copy the code
Bean. The XML file
<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">
<! -- Introducing external attribute tags -->
<context:property-placeholder location="classpath:jdbc.properties" />
<! -- Configure connection pool -->
<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>
Copy the code