无法自动配置DataSource:未指定“spring.datasource.url” [英] Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified

查看:6741
本文介绍了无法自动配置DataSource:未指定“spring.datasource.url”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Web,MongoDB和JPA依赖项从 SPRING INITIALIZR 创建了一个基本的Spring启动应用程序。

I have created a basic spring boot application from SPRING INITIALIZR with the Web, MongoDB and JPA dependencies.

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

When I try to run the spring boot application I am getting the following exception:

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文件中,我有以下配置:

In application.properties file I am having the following configuration:

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 Boot:2.0

Versions which I use: Spring : 5.0.4, MongoDB : 3.6, Spring Boot: 2.0

推荐答案

由于您在pom.xml文件中添加了mongodb和data-jpa依赖项,因此它创建了依赖性冲突,如下所示

Since you have added both mongodb and data-jpa dependencies in your pom.xml file, it was creating a dependency conflict like below

<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依赖项并运行。它应该可以正常工作。

Try removing jpa dependency and run. It should work fine.

这篇关于无法自动配置DataSource:未指定“spring.datasource.url”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆