Spring Boot错误——SpringBoot 2.0 报错: Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

摘要:
背景使用SpringCloud搭建微服务,服务的注册与发现(Eureka)项目启动时报错,错误如下***************************APPLICATIONFAILEDTOSTART***************************Description:FailedtoconfigureaDataSource:'url'attributeisnotspecifiedandn

背景

  • 使用Spring Cloud搭建微服务,服务的注册与发现(Eureka)项目启动时报错,错误如下
    ***************************APPLICATION FAILED TO START
    ***************************
    Description:
    
    Failed to configure a DataSource: 'url'attribute is not specified and no embedded datasource could be 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).

报错原因

  • 在网上找了解决方法,出现这个错误一般会是下面几种原因
    • 原因一:Spring Boot的配置,DataSourceAutoConfiguration会自动加载数据源
      • Spring boot 启动时会默认加载org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration这个类,DataSourceAutoConfiguration类使用了@Configuration注解向spring注入了dataSource bean。如果在项目配置文件中找不到数据源信息,项目在启动时就会报错
    • 原因二:在application.properties/或者application.yml文件中没有添加数据库配置信息
      • Spring Boot会自动加载classpath中配置文件中的数据源信息,如果找不到对应的数据源信息,就会报错
    • 因为我搭建的是 服务的注册与发现(Eureka)项目,项目中不需要进行数据源配置,所以报错的是原因一:Spring Boot配置中的DataSourceAutoConfiguration自动加载数据源,却找不到数据源信息导致的

解决方法

  • 在Spring Boot启动类加上注解@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class}),代表在启动时不需要项目自动加载数据源即可
@EnableEurekaServer
@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
public classEurekaApplication {
    public static voidmain(String[] args) {
        SpringApplication.run(EurekaApplication.class, args);
    }
}
  • Next

免责声明:文章转载自《Spring Boot错误——SpringBoot 2.0 报错: Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Manjaro 安装 & 配置Vue CLI 3开发中屏蔽的EsLint错误 (.eslintrc.js 在vue3+中 修改这个)下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

xcode模拟器不显示键盘解决方案

当我们使用Xcode进行开发时,我们并不总是需要在iPhone上运行代码。有时模拟器可以解决这些问题。但当你使用模拟器时,你会发现,如果你使用模拟器上的键盘在TextFiled中输入信息,这是可以的,但如果你使用键盘输入信息,那么你会发现模拟器上的屏幕将不再显示。这是因为默认情况下,xcode使用计算机键盘作为外部键盘,不会弹出虚拟键盘。...

.NET5 ABP框架(一)

授权-ABP可以以声明的方式检查权限。如果发生异常,ABP将自动记录并向客户机返回适当的结果。默认情况下,ABP使用Log4Net写入日志。当然,我们也可以通过修改配置来使用其他日志框架。除了本示例中显示的ABP的优点之外,ABP还提供了一个健壮的基础架构和应用程序模型。...

Selenium操作示例——鼠标悬停显示二级菜单,再点击二级菜单或下拉列表

这两天在python中玩selenium时,我遇到了一个问题,那就是鼠标移动到页面上的一个按钮或菜单,二级菜单或下拉菜单自动弹出,然后二级菜单或者下拉列表自动点击。...

Ubuntu安装时怎样分区

应该首先放置启动分区。并将引导设置为主分区。如果是双系统或多系统安装,通常可以选择逻辑分区。首先,Grub可以在1024柱面后面引导Linux内核;第二,即使有多个Linux安装,/boot也可以完全不共享。此外,非独立/引导分区仅占用根文件夹下约20MB的空间。所以决定是否启动。...

CefSharp 浏览器核心,爬虫

CefSharp是什么Aframeworkforembeddingweb-browsing-likecapabilitiestoastandard.NETapplication(WPForWindowsForms).Asetofhigh-levelcustomcontrolstomakeitreasonablyeasytointegratethesecapa...

vue 数组push元素 视图没更新

Vue包含一组用于观察数组的变异方法,因此它们也会触发视图更新。这些方法如下:push()pop()shift()unshift()split()sort()reverse()问题描述:在tap列下,向每个选项卡添加一行数据,可以一直添加默认行。切换到选项卡1时,阵列已成功添加,但视图未更改。来回切换后手动更新分析:由于JavaScript限制,Vue无法检...