spring boot 2.x版本:启动报错:Error creating bean with name 'dataSource' defined in class path resource

#在使用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 #就是修改了这一行

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值