SpringBoot - Failed to determine a suitable driver class
Posted 放羊的牧码
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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)
原因分析
启动时加载配置文件失败,异常报错,启动失败(网上有些人遇到启动时本不需要加载数据源,却加载了,导致这个问题)
解决方案
- 方法一(启动时加载本不需要加载的数据源)
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class SpringBootApplication
public static void main(String[] args)
SpringApplication.run(MySpringBootApplication.class,args);
Ps:exclude = DataSourceAutoConfiguration.class 加上这段代码,去掉数据源
- 方法二(有数据源依旧报错,配置文件没有加载成功)
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>*</include>
<include>*/*</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M1</version>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<testIncludes>
<testInclude>none</testInclude>
</testIncludes>
<compilerArguments>
<extdirs>$project.basedir/src/main/webapp/WEB-INF/lib</extdirs>
</compilerArguments>
</configuration>
</plugin>
</plugins>
</build>
Ps:可以尝试在pom.xml文件的build标签中加入以上内容
以上是关于SpringBoot - Failed to determine a suitable driver class的主要内容,如果未能解决你的问题,请参考以下文章
Springboot:解决Failed to load ApplicationContext问题
SpringBoot+WebSocket问题:Failed to register @ServerEndpoint class
SpringBoot启动异常:Reason: Failed to determine a suitable driver class
SpringBoot启动报错Failed to determine a suitable driver class
SpringBoot启动报错Failed to determine a suitable driver class
SpringBoot解决Failed to start bean ‘documentationPluginsBootstrapper‘; nested exception is java.lang.N