#在使用spingBoot 2.x版本的时候,使用alibaba的druid数据库连接池,com.github.pagehelper的分页插件1.1.2版本,启动项目报错。
错误日志如下:
Error creating bean with name 'dataSource' defined in class path resource [com/alibaba/druid/spring/boot/autoconfigure/DruidDataSourceAutoConfigure.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/boot/bind/RelaxedDataBinder
解决方案一:使用jdbc连接
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
解决方案二:boot版本改为1.5.x版本
解决方案3:
第一步、把druid连接池版本更新到最新1.1.13
第二步、分页插件更新到1.2.3
<!-- 分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.3</version>
</dependency>
<!-- alibaba的druid数据库连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.13</version>
</dependency>
第三步、使用com.mysql.cj.jdbc.Driver(application.yml文件)
datasource:
name: test
url: jdbc:mysql://127.0.0.1:3306/hometeach?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8
username: root
password: 123456
# 使用druid数据源
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
来源:CSDN
作者:会飞的鱼__
链接:https://blog.csdn.net/qq_33637730/article/details/103595833