Cannot resolve class 'HikariDataSource' in yml

Table of contents

 Cannot resolve class 'HikariDataSource' in yml 

⭐Information about HikariDataSource


 Cannot resolve class 'HikariDataSource' in yml 

Before the modification, the line was red 

specific code 

# 配置项目信息
spring:
  profiles:
    active: prod   # yml中配置文件的环境配置,dev:开发环境,test:测试环境,prod:生产环境
  application:
    name: imooc-news-dev-service-user
  datasource:                                         # 数据源的相关配置
    type: com.zaxxer.hikari.HikariDataSource         # 数据源类型:HikariCP
    driver-class-name: com.mysql.cj.jdbc.Driver         # mysql驱动
    url: jdbc:mysql://localhost:3306/imooc-news-dev?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true
    username: root
    password: 123456
    hikari:
      connection-timeout: 30000       # 等待连接池分配连接的最大时长(毫秒),超过这个时长还没可用的连接则发生SQLException, 默认:30秒
      minimum-idle: 5                 # 最小连接数
      maximum-pool-size: 20           # 最大连接数
      auto-commit: true               # 自动提交
      idle-timeout: 600000            # 连接超时的最大时长(毫秒),超时则被释放(retired),默认:10分钟
      pool-name: DateSourceHikariCP     # 连接池名字
      max-lifetime: 1800000           # 连接的生命时长(毫秒),超时而且没被使用则被释放(retired),默认:30分钟 1800000ms
      connection-test-query: SELECT 1
  jackson:
    date-format: yyyy-MM-dd HH:mm:ss
    time-zone: GMT+8

After searching for relevant information, it was found that the relevant dependencies of jdbc were not introduced

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

No error will be reported after adding

⭐Information about HikariDataSource

Refer to the following article

First understanding of HikariDataSource - mushishi - Blog Park (cnblogs.com) 

Troubleshoot HikariDataSource abnormal closure problem - short book (jianshu.com) 

  • HikariCP is a database connection pool for jdbc api , so it must implement  the interface  javax.sql.DataSource
  • The DataSource provided in Hikari is HikariDataSource, HikariDataSource implements HikariConfig, and the timeout configuration of various parameters of the database is in HikariaConfig.
  • Two initialization methods are provided, one is the default constructor, when a single new HikariDataSource is created, the link to the data source will not be established, and it needs to wait until the getConnection method of HikariDataSource is called for the first time. The relevant information after the data source is established is saved in the variable HikariPool pool in HikariDataSource.
  • Another way to build is to call the constructor with HikariConfig, which is suitable for building multiple data sources and sharing the same configuration. In this way, the link to the data source is established when the constructor is called.
  • All data source acquisition of HikariDataSource is entrusted to HikariPool. A data source will have a HikariPool, a HikariPool has a ConcurrentBag, a ConcurrentBag has multiple PoolEntry, and a PoolEntry corresponds to a Connection.

Guess you like

Origin blog.csdn.net/m0_52982868/article/details/127941442