Springboot connects to the database error: testWhileIdle is true, validationQuery not set

Problem Description:

  Use springboot to connect to the database, an error is reported when starting: testWhileIdle is true, validationQuery not set. But it does not affect the use of the system, and all access to the database is normal.

  The application.properties data source configuration is as follows:

  spring.datasource.username=root
  spring.datasource.password=
  spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
  spring.datasource.initial-size=1
  spring.datasource.maximum-pool-size=10
  spring.datasource.connection-timeout=5000

 

Solution:

springboot1.4 cancel spring.datasource.type

  In the new version, the validationQuery is not automatically injected, so you need to manually declare the datasource bean. As for how to write, you can read the above article.

  It is mainly to manually inject DruidDataSource, declare a configuration class, inject all values ​​of the data source into it, and return to DruidDataSource.

  Restart, the system does not report an error!

  Finally, I checked the DruidDataSource source code,

  public static final String DEFAULT_VALIDATION_QUERY = null;

  Sure enough, the DruidDataSource default testWhileIdle=true, and the validationQuery is set to empty.

Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *