开发手册 欢迎您!
软件开发者资料库

Java Spring Boot 2.0 异常 auto-configure a DataSource: 'spring.datasource.url' is not specified

本文主要介绍执行Spring Boot程序(Spring : 5.0.4, MongoDB : 3.6, Spring Boot: 2.0)报错问题解决方法,异常信息:Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified and no embedded datasource could be auto-configured.

1、异常信息

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-03-25 16:27:02.807 ERROR 16256 --- [ restartedMain] 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 situation:
If you want an embedded database like H2, HSQL or Derby, please add it in the Classpath.
If you have database settings to be loaded from a particular profile you may need to activate it since no profiles were currently active.

2、mongodb和data-jpa依赖项冲突

pom.xml文件中添加了mongodbdata-jpa依赖项,因此它创建了一个依赖项冲突,如下所示:


org.springframework.boot
spring-boot-starter-data-jpa


org.springframework.boot
spring-boot-starter-data-mongodb

尝试删除jpa依赖项并运行。应该工作正常。

3、application.properties文件配置问题

resources文件夹下的application.properties文件中添加以下行,然后重新启动应用程序:

spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration