java - 自动配置数据源失败 : 'spring.datasource.url' is not

我从 SPRING INITIALIZR 创建了一个基本的 Spring Boot 应用程序,其中包含 Web、MongoDB 和 JPA 依赖项。

当我尝试运行 spring boot 应用程序时,出现以下异常:

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.

在 application.properties 文件中,我有以下配置:

server.port=8081
spring.data.mongodb.database=TestDatabase
spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017

我使用的版本: Spring :5.0.4, MongoDB:3.6, Spring 启动:2.0

最佳答案

由于您在 pom.xml 文件中添加了 mongodb 和 data-jpa 依赖项,因此会产生如下所示的依赖项冲突

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>

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

关于java - 自动配置数据源失败 : 'spring.datasource.url' is not specified,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49475177/

相关文章:

ruby-on-rails - Mongoid 3 + Heroku (MongoHQ) 导致 Mo

mongodb - mongoexport 聚合导出到 csv 文件

shell - MongoDB 正在运行但无法使用 shell 连接

ubuntu - MongoDB 仅在 Ubuntu 上以 root 身份运行时才有效 - 数据目录

ubuntu - 为什么我不能启动mongodb

mongodb - 在 MongoDB 中存储日期的最佳方式是什么?

mongodb - 在键值数据存储中存储目录层次结构

javascript - 如何在 Mongoose 模型中定义方法?

mongodb - 在MongoDB中获取数组的第n个元素

node.js - 如何在 Mongoose 中执行 id 数组查询?