Reason: Failed to determine a suitable driver class

本来运行好好的项目,下一次运行却报错了。
在这里插入图片描述
报错原因:
Description:
Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class

看到报错原因,检查过了数据库源配置的编写,也没有错误。
上一次是可以成功运行的,但是这一次就不能运行了。
找了很多资料,发现有可能是 maven 编译项目出现了问题。

这是最新编译的 class 文件,跟下面对比少了 .yml 等其它的配置文件
说明 resources 文件夹没有被扫描到。
在这里插入图片描述
而刚新创建的SpringBoot项目是下面这样的(我更改了配置后缀名 .yml):
在这里插入图片描述
解决的办法:
1、在 pom.xml 里面添加扫描配置文件的操作。不过我试过好像不行。

<build>
        <resources>
            <resource>
                <directory>${basedir}/src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.yml</include>
                    <include>**/*.properties</include>
                </includes>
            </resource>
            <resource>
                <directory>${basedir}/src/main/resources</directory>
                <includes>
                    <include>**/*.yml</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

2、重新生成一个SpringBoot项目,然后将原本项目移过去。

附上 application.yml 的配置内容

mybatis:
  mapper-locations: classpath:/mapper/*.xml
  type-aliases-package: {此处我填写了存储实体的包}

spring:
  main:
    allow-bean-definition-overriding: true

  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/
    {此处填写连接名称}
    ?allowPublicKeyRetrieval=true
    &useAffectedRows=true
    &serverTimezone=GMT%2B8
    &allowMultiQueries=true
    &useUnicode=true
    &characterEncoding=UTF-8&useSSL=false
    username: root
    password: 123456
    type: com.alibaba.druid.pool.DruidDataSource
    druid:
      initial-size: 5
      min-idle: 5
      max-wait: 60000
      max-active: 20
      test-on-borrow: false
      test-on-return: false
      test-while-idle: true
      time-between-eviction-runs-millis: 60000
      min-evictable-idle-time-millis: 30000
      pool-prepared-statements: true
      max-pool-prepared-statement-per-connection-size: 20
      connection-properties: druid.stat.mergeSql=true
      filter:
        stat:
          merge-sql: true
          slow-sql-millis: 5000

      use-global-data-source-stat: true

server:
  port: 8000

补充:
第二个方法项目小点的话还可以,直接复制黏贴整个项目,不用做太多改动。
不过还是希望不要再发生了。

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值