当我尝试运行spring boot应用程序时,我得到了以下错误
starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2018-05-03 10:50:09.457 ERROR 4909 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
*************************** APPLICATION FAILED TO START
***************************
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).发布于 2018-05-03 14:01:43
如果您想要使用非嵌入式数据源,上述答案是正确的。如果要使用嵌入式数据源,则只需向pom.xml添加以下依赖项
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>如果您想在测试中使用嵌入式数据源,那么将作用域更改为test而不是runtime。
发布于 2018-05-03 13:54:09
如果您希望自动配置数据源,请将配置详细信息放在application.properties文件中。如下所示(MySQL的配置)
spring.datasource.url=jdbc:mysql://localhost/test
spring.datasource.username=dbuser
spring.datasource.password=dbpass
spring.datasource.driver-class-name=com.mysql.jdbc.Driverhttps://stackoverflow.com/questions/50147762
复制相似问题