Why SpringBoot’s Default Druid Settings Fail and How to Fix Them

The article explains how default Druid connection‑pool settings in a SpringBoot project can leave the pool uninitialized, shows the hidden pitfalls, and provides the exact Maven dependencies and configuration properties needed to correctly enable and tune Druid, including enabling its monitoring console.

Senior Brother's Insights
Senior Brother's Insights
Senior Brother's Insights
Why SpringBoot’s Default Druid Settings Fail and How to Fix Them

Background and Problem

When taking over a project built by an outsourced team, the author discovered that integrating Druid with SpringBoot using the official starter appeared to work at first— the application started and the business logic ran—yet the connection‑pool behaved incorrectly because critical pool parameters were left at their defaults.

Required Maven Dependencies

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!-- Database related -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
</dependency>

<!-- Druid integration -->
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid-spring-boot-starter</artifactId>
    <version>1.1.21</version>
</dependency>

Initial (Faulty) Configuration

spring.datasource.url=jdbc:mysql://localhost:3306/spring?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=true
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource

These properties look correct, so the application starts, but the Druid pool defaults to initial-size=0 and min-idle=0, meaning no connections are pre‑created.

Enabling Druid’s Monitoring Console

# Enable StatViewServlet (monitoring page)
spring.datasource.druid.stat-view-servlet.enabled=true
# Login credentials for the console
spring.datasource.druid.stat-view-servlet.login-username=admin
spring.datasource.druid.stat-view-servlet.login-password=admin

After restarting, the console is reachable at http://localhost:8080/druid/login.html. The following screenshots show the login page and the “Data Source” view where the default values (initial‑size 0, min‑idle 0, max‑active 8) are visible.

Druid login page
Druid login page
Druid data source view
Druid data source view

Correct Pool Configuration

# Connection pool settings
spring.datasource.druid.initial-size=3
spring.datasource.druid.min-idle=3
spring.datasource.druid.max-active=10
spring.datasource.druid.max-wait=60000

Applying these values and restarting the application aligns the runtime pool statistics with the configuration, as shown in the updated console screenshot.

Updated Druid pool view
Updated Druid pool view

How the Issue Was Discovered

The problem surfaced while refactoring multiple logging frameworks (logback, log4j, log4j2). The application started but produced no logs and appeared unresponsive. Investigation revealed that the datasource URL was wrong, yet no exception was thrown because initial-size had been set to 0, preventing an early connection attempt.

# initialization size set to 0
spring.datasource.druid.initial-size=0

When initial-size is zero, Druid does not try to open a connection during startup, so connection‑related errors are silently ignored.

Takeaway

When inheriting messy code, always inspect and adjust low‑level configuration such as connection‑pool parameters; otherwise hidden defaults can cause subtle runtime issues. Probing the root cause yields more valuable knowledge than merely fixing the symptom.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaConfigurationSpringBootDruidDatabaseConnectionPool
Senior Brother's Insights
Written by

Senior Brother's Insights

A public account focused on workplace, career growth, team management, and self-improvement. The author is the writer of books including 'SpringBoot Technology Insider' and 'Drools 8 Rule Engine: Core Technology and Practice'.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.