• SpringBoot - Failed to determine a suitable driver class


    报错问题

    关键信息:Description: Failed to auto-configure a DataSource: ‘spring.datasource.url’ is not
    specified and no embedded datasource could be auto-configured.

    Reason: Failed to determine a suitable driver class

    Action: Consider the following: If you want an embedded database (H2, HSQL or
    Derby), please put it on the classpath. If you have database settings
    to be loaded from a particular profile you may need to activate it (no
    profiles are currently active)

    原因分析

    启动时加载配置文件失败,异常报错,启动失败(网上有些人遇到启动时本不需要加载数据源,却加载了,导致这个问题)

    解决方案

    • 方法一(启动时加载本不需要加载的数据源)
    1. @SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
    2. public class SpringBootApplication {
    3. public static void main(String[] args) {
    4. SpringApplication.run(MySpringBootApplication.class,args);
    5. }
    6. }

    Ps:exclude = DataSourceAutoConfiguration.class 加上这段代码,去掉数据源

    • 方法二(有数据源依旧报错,配置文件没有加载成功)
    1. <build>
    2. <resources>
    3. <resource>
    4. <directory>src/main/java</directory>
    5. <includes>
    6. <include>**/*.properties</include>
    7. <include>**/*.xml</include>
    8. </includes>
    9. <filtering>true</filtering>
    10. </resource>
    11. <resource>
    12. <directory>src/main/resources</directory>
    13. <includes>
    14. <include>*</include>
    15. <include>*/*</include>
    16. </includes>
    17. <filtering>true</filtering>
    18. </resource>
    19. </resources>
    20. <plugins>
    21. <plugin>
    22. <groupId>org.apache.maven.plugins</groupId>
    23. <artifactId>maven-surefire-plugin</artifactId>
    24. <version>3.0.0-M1</version>
    25. <configuration>
    26. <useSystemClassLoader>false</useSystemClassLoader>
    27. </configuration>
    28. </plugin>
    29. <plugin>
    30. <groupId>org.apache.maven.plugins</groupId>
    31. <artifactId>maven-compiler-plugin</artifactId>
    32. <version>3.3</version>
    33. <configuration>
    34. <source>1.8</source>
    35. <target>1.8</target>
    36. <encoding>UTF-8</encoding>
    37. <testIncludes>
    38. <testInclude>none</testInclude>
    39. </testIncludes>
    40. <compilerArguments>
    41. <extdirs>${project.basedir}/src/main/webapp/WEB-INF/lib</extdirs>
    42. </compilerArguments>
    43. </configuration>
    44. </plugin>
    45. </plugins>
    46. </build>

    Ps:可以尝试在pom.xml文件的build标签中加入以上内容

  • 相关阅读:
    acwing算法基础之数据结构--堆算法
    C#学习相关系列之Linq用法---where和select用法(二)
    RabbitMQ集群搭建详细介绍以及解决搭建过程中的各种问题 + 配置镜像队列——实操型
    Java8特性,Stream流的使用,收集成为map集合
    2024/2/18 图论 最短路入门 dijkstra 2
    Android ADB常用命令
    Web服务(Web Service)
    kubernetes(K8S)学习笔记P5:K8s核心概念2
    关于系统架构
    JavaScript-变量的作用域、let、const详解
  • 原文地址:https://blog.csdn.net/Dream_Weave/article/details/125620487