• 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标签中加入以上内容

  • 相关阅读:
    Mysql事务
    android 12动态开关USB网络共享
    JavaEE-多线程-阻塞队列
    Matlab:tftb-0.2时频工具箱安装小记
    关于将预留单中增强字段带入物料凭证和会计凭证中
    【C语言】职工管理系统详解(文件操作)
    自定义功能区
    P3385 【模板】负环
    用Maloja创建音乐收听统计数据
    Docker安装、启动、管理ElasticSearch、ElasticSearch-heade、kibana
  • 原文地址:https://blog.csdn.net/Dream_Weave/article/details/125620487