Spring configuration Druid (Druid) Database Connectivity

A configuration:

<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
          destroy-method="close" lazy-init="false">
        <property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql:///jdbc?serverTimezone=UTC"/>
        <property name="username" value="root"/>
        <property name="password" value="qisini"/>
        <property name="initialSize" value="3" />
        <property name="maxActive" value="5" />
        <property name="maxWait" value="3000" />
    </bean>

Second way:
First, the configuration file: jdbcConfiguration.properties

jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/jdbc?serverTimezone=UTC
jdbc.username=root
jdbc.password=qisini
<context:property-placeholder location="classpath:jdbcConfiguration.properties"></context:property-placeholder>
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
          destroy-method="close" lazy-init="false">
        <property name="driverClassName" value="${jdbc.driver}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
        <property name="initialSize" value="3" />
        <property name="maxActive" value="5" />
        <property name="maxWait" value="3000" />
    </bean>

Possible errors:

java.sql.SQLException: Access denied for user ‘’@‘localhost’ (using password: YES)

the reason:

<property name="username" value="${jdbc.username}"/>

This property is in the name="username"writtenname=“name”

Published 141 original articles · won praise 131 · views 210 000 +

Guess you like

Origin blog.csdn.net/qq_41621362/article/details/103501281