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

  • 相关阅读:
    JavaSE_第7章 面向对象基础(下)
    云中马在A股上市:总市值约为40亿元,叶福忠为实际控制人
    软件测试之性能测试面试题合集(含答案分析细节)
    随手笔记(四十五)——idea git冲突
    电脑上使用的备忘记事软件哪一款好用点?
    C语言assert断言
    「Verilog学习笔记」使用函数实现数据大小端转换
    PHP explode (多)分隔符(delimiters) 使用
    虾皮shopee获得店铺的所有商品 API 返回值说明
    六十六、vue组件
  • 原文地址:https://blog.csdn.net/Dream_Weave/article/details/125620487